-
Notifications
You must be signed in to change notification settings - Fork 0
/
SystemF.mana
60 lines (43 loc) · 1.7 KB
/
SystemF.mana
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
------------------------------------------------------------------------------
-- System F
------------------------------------------------------------------------------
import Core
------------------------------------------------------------------------------
-- inductive types in system F
------------------------------------------------------------------------------
Mu : (Type -> Type) -> Type
Mu f = (a : Type) -> (f a -> a) -> a
foldMu : (f a -> a) -> Mu f -> a
foldMu faa muf = muf a faa
inMu : Functor f => f (Mu f) -> Mu f
inMu fmuf a faa = faa (map (foldMu faa) fmuf)
--inMu fmuf a faa = faa fa
-- where
-- g = foldMu faa : Mu f -> a
-- h = map g : f (Mu f) -> f a
-- fa = h fmuf : f a
------------------------------------------------------------------------------
-- type Lst v = Nl | Cns v (Lst v)
------------------------------------------------------------------------------
type ListF v a = NlF | CnsF v a
instance Functor (ListF v) where
map f (NlF ) = NlF
map f (CnsF v a) = CnsF v (f a)
Lst : Type -> Type
Lst v = Mu (ListF v)
Nl : Lst a
Nl = inMu NlF
Cns : v -> Lst v -> Lst v
Cns x xs = inMu (CnsF x xs)
fromLst : Lst a -> List a
fromLst la = la (List a) go
where
go : ListF a (List a) -> List a
go (NlF ) = Nil
go (CnsF x xs) = Cons x xs
_ = Reflexive : fromLst (Cns 'a' <| Cns 'b' <| Cns 'c' Nl) = [ 'a', 'b', 'c' ]
------------------------------------------------------------------------------
-- type Mu t = Mu (Mu t -> t)
------------------------------------------------------------------------------
-- MuF isn't a functor so it does't generate an inductive type
type MuF t a = MuF (a -> t)