| 1 |
Set Dump Bytecode. |
| 2 |
Set Printing Universes. |
| 3 |
Set Printing All. |
| 4 |
|
| 5 |
Polymorphic Class Applicative@{d c} (T : Type@{d} -> Type@{c}) := |
| 6 |
{ pure : forall {A : Type@{d}}, A -> T A |
| 7 |
; ap : forall {A B : Type@{d}}, T (A -> B) -> T A -> T B |
| 8 |
}. |
| 9 |
|
| 10 |
Universes Uo Ua. |
| 11 |
|
| 12 |
Eval compute in @pure@{Uo Ua}. |
| 13 |
|
| 14 |
Global Instance Applicative_option : Applicative@{Uo Ua} option := |
| 15 |
{| pure := @Some |
| 16 |
; ap := fun _ _ f x => |
| 17 |
match f , x with |
| 18 |
| Some f , Some x => Some (f x) |
| 19 |
| _ , _ => None |
| 20 |
end |
| 21 |
|}. |
| 22 |
|
| 23 |
Definition foo := ap (ap (pure plus) (pure 1)) (pure 1). |
| 24 |
|
| 25 |
Print foo. |
| 26 |
|
| 27 |
|
| 28 |
Eval vm_compute in foo. |