2
%if False %% only to be seen by the Haskell compiler
8
We are using the functions in Haskell to represent the functional
9
values in the core language.
11
Constants (i.e. either explicitly defined (abbreviations), implicitly
12
defined (recursively defined or data types) are represented together
13
with their concrete name (a string) and their type (which is a
14
value). A generic value is represented in the same way, except that it
15
also have an integer which is used to distinguish it from other
18
The set of values is defined by the following domain equation:
20
\Val = \lambda\ ( \Val\ \to\ \Val)
21
||\ \App\ \Hh\ \Val ^*\ ||\ \Set\
22
||\ \Fun\ \Val\ (\Val\ \to \Val)
24
This can be expressed in Haskell by the following data type:
30
| Fun Val (Val -> Val)
32
The head of a function application is either a constant or a generic
33
variable. In both cases it is represented as a name together with
34
its type. A generic variable comes together with an integer to distinguish it
35
from other generic variables. We use the function |typH| to
36
compute the type of a head.
39
Gen Int Name Val -- generic variables
40
| Const Name Val -- constants
41
eqH :: Head -> Head -> Bool
42
eqH (Gen n1 _ _) (Gen n2 _ _) = n1 == n2
43
eqH (Const s1 _) (Const s2 _) = s1 == s2
52
We need functions to convert a constant and a type to a head applied
58
mconst :: Name -> Val -> Val
59
mconst s v = mvar (Const s v)
61
The expression |apps v [v1; ...; vn]| computes the application
64
apps :: Val -> [Val] -> Val
66
apps (Lam f) (u:us) = apps (f u) us
67
apps (App h us) vs = App h (us ++ vs)
69
app :: Val -> Val -> Val
70
app u1 u2 = apps u1 [u2]
72
The expression |itCurry|
78
itCurry :: Val -> Val -> (Val -> Val) -> Val
79
itCurry u (Fun v g) f = Fun v (\ w -> itCurry (app u w) (g w) f)
82
inst :: Val -> [Val] -> Val
84
inst (Fun _ f) (u:us) = inst (f u) us