Skyb0rg

Untitled

Jan 22nd, 2021
872
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (* Structure subtyping *)
  2.  
  3. signature SIG1 = sig
  4.     type t
  5.     val x : t
  6. end
  7.  
  8. signature SIG2 = sig
  9.     val x : int
  10. end
  11.  
  12. signature SIG1AND2 = sig
  13.     type t = int
  14.     val x : t
  15. end
  16.  
  17. functor F(X : SIG1AND2) = struct
  18.     structure A : SIG1 = X
  19.     structure B : SIG2 = X
  20. end
  21. (* functor F : SIG1AND2 -> (sig structure A : SIG1 and B : SIG2 end) *)
  22.  
  23. fun f X =
  24.     let structure A as SIG1 = X
  25.         structure B as SIG2 = X (* Type error here *)
  26.     in  ()
  27.     end
  28. (* Type mismatch, X must have both types: [ SIG1 ] and [ SIG2 ] *)
  29.  
RAW Paste Data