-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgramType.idr
62 lines (46 loc) · 1.51 KB
/
ProgramType.idr
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
61
62
module LICK.ProgramType
%default total
||| The primitive types within the language are given explicitly with
||| this data type. User-defined types will be built from these.
public export
data ProgramType : Type where
||| A function between two types.
PFunction
: (input : ProgramType)
-> (output : ProgramType)
-> ProgramType
||| The integer type.
PInt : ProgramType
||| If the domains don't match, the functions definitely don't.
domainsDoNotMatch
: Not ( i = i' )
-> Not (PFunction i o = PFunction i' o')
domainsDoNotMatch f Refl
= f Refl
||| If the codomains don't match, the functions definitely don't.
codomainsDoNotMatch
: Not ( o = o')
-> Not (PFunction i o = PFunction i' o')
codomainsDoNotMatch f Refl
= f Refl
||| A function is not an integer.
functionIsNotInt
: Not (PFunction i o = PInt)
functionIsNotInt Refl impossible
||| Decidable equality on program types.
public export
implementation DecEq ProgramType where
decEq PInt PInt
= Yes Refl
decEq PInt (PFunction i o)
= No (functionIsNotInt . sym)
decEq (PFunction i o) PInt
= No functionIsNotInt
decEq (PFunction i o) (PFunction i' o')
with (decEq i i', decEq o o')
decEq (PFunction i o) (PFunction i o)
| (Yes Refl, Yes Refl) = Yes Refl
decEq (PFunction i _) (PFunction i' _)
| (No contra, _) = No (domainsDoNotMatch contra)
decEq (PFunction _ o) (PFunction _ o')
| (_, No contra) = No (codomainsDoNotMatch contra)