32 lines
988 B
Coq
32 lines
988 B
Coq
Require Import Extraction.
|
|
Require Import ExtrHaskellBasic.
|
|
Require Import ExtrHaskellNatInt.
|
|
Extraction Language Haskell.
|
|
|
|
Class Functor (f: Type -> Type) := {
|
|
fmap : forall {A B:Type}, (A -> B) -> f A -> f B
|
|
}.
|
|
|
|
Class Applicative (f: Type -> Type) `{Functor f} :=
|
|
{
|
|
pure: forall {A:Type}, A -> f A;
|
|
ap: forall {A B:Type}, f (A -> B) -> f A -> f B
|
|
}.
|
|
|
|
#[export] Instance option_functor : Functor option := {
|
|
fmap {A B:Type} f x :=
|
|
match x with
|
|
| Some x' => Some (f x')
|
|
| None => None
|
|
end
|
|
}.
|
|
|
|
Definition optS (f:nat -> nat) (a: option nat): option nat :=
|
|
fmap f a.
|
|
Compute optS S (Some 3).
|
|
|
|
Recursive Extraction optS.
|
|
Extract Inductive Functor => Functor [ fmap ].
|
|
Recursive Extraction optS.
|
|
|