Advertisement
tinyevil

Untitled

Mar 1st, 2018
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- "basic" or "regular" sum type
  2. type Nat
  3.     O
  4.     S (n:Nat)
  5.  
  6. -- structural subtype of a sum type
  7. type EvenNat (< Nat)
  8.     O
  9.     S (S (n:EvenNat))
  10.    
  11. type Positive (< Nat)
  12.     S O
  13.     S (p:Positive)
  14.  
  15. -- another basic type
  16. type Reward
  17.     Nothing
  18.     Coins(num:Positive)
  19.     Item(id:String)
  20.  
  21. -- supertype of a sum type
  22. -- by adding more constructor
  23. type LootReward (> Reward)
  24.     Exp(amount:Positive)
  25.    
  26. -- subtype of a sum type (adding extra field to each constructor)
  27. type RewardWithPostcard (< Reward)
  28.     + message:String
  29.    
  30.     -- Nothing(message:String)
  31.     -- Coins(num:Positive, message:String)
  32.     -- Item(id:String, message:String)
  33.  
  34. -- propositional subtyping
  35.  Subtype A B ==
  36.     exists coerce : A -> B,
  37.         downcast : B -> maybe A,
  38.         forall a:A, downcast (coerce a) = Some a
  39.     -- there is one caveat with propositional subtyping
  40.     -- it is not necessarily transitive, i.e. for A, B, C, if there are coercions A->B, B->C and A->C,
  41.     -- it could be "coerce_B_C (coerce_A_B a) <> coerce_A_C a"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement