Advertisement
Nolrai

Program Monad

May 21st, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. axiom ext : ∀ A B (f g : Π x : A, B x), (∀ x, f x = g x) -> f = g
  2.  
  3. inductive Prompt (inst) : Type -> Type :=
  4. | Ret {} : Π r,
  5. Prompt inst r
  6. | Bind : Π {a r},
  7. (a -> Prompt inst r) -> (Prompt inst a) -> (Prompt inst r)
  8. | Tag : Π {r}, inst r -> Prompt p r
  9.  
  10. -- reverse concat, allso known as "then"
  11. infixl `∙`:50 := fun f g x := g (f x)
  12.  
  13. structure functor (F : (Type -> Type)) : Type :=
  14. (fmap : Π A B, (f : A -> B) -> F A -> F B)
  15. (id_rule : ∀ A, fmap id = (id : F A -> F A))
  16. (comp_rule : ∀ f g, fmap (f ∙ g) = (fmap f) ∙ (fmap g))
  17.  
  18. end
  19.  
  20. abbreviation Prompt := Type -> Type -> Type
  21.  
  22. definition type_has_zero : has_zero Type₁ :=
  23. {| has_zero Type₁, zero := empty |}
  24.  
  25. definition type_has_one [instance] : has_one Type₁ :=
  26. {| has_one Type₁, one := unit |}
  27.  
  28. definition type_has_add [instance] : has_add Type :=
  29. {| has_add Type, add := sum |}
  30.  
  31. inductive StateP (S : Type₁) : Type₁ -> Type₁ -> Type₁ :=
  32. | Get : StateP S S
  33. | Set : StateP S (S -> 1)
  34.  
  35. abbreviation StateM S := FreeM (StateP S)
  36.  
  37. definition
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement