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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
module FlatCurry.Typed.Build where
import Data.IORef
import Data.List ( find, nub )
import Data.Maybe ( fromJust )
import FlatCurry.Annotated.Goodies
import System.CurryPath ( getLoadPathForModule, lookupModuleSource
, stripCurrySuffix )
import System.FilePath ( (</>) )
import FlatCurry.Typed.Goodies ( pre )
import FlatCurry.Typed.Types
infixr 9 ~>
baseType :: QName -> TypeExpr
baseType t = TCons t []
(~>) :: TypeExpr -> TypeExpr -> TypeExpr
t1 ~> t2 = FuncType t1 t2
unitType :: TypeExpr
unitType = baseType (pre "()")
charType :: TypeExpr
charType = baseType (pre "Char")
boolType :: TypeExpr
boolType = baseType (pre "Bool")
listType :: TypeExpr -> TypeExpr
listType a = TCons (pre "[]") [a]
stringType :: TypeExpr
stringType = listType charType
tupleType :: [TypeExpr] -> TypeExpr
tupleType ts
| n==0 = baseType (pre "()")
| n==1 = head ts
| otherwise = TCons (tupleCons n) ts
where n = length ts
tupleCons :: Int -> QName
tupleCons n = pre ('(' : take (n-1) (repeat ',') ++ ")")
tupleExpr :: [TAExpr] -> TAExpr
tupleExpr xs = case length xs of
0 -> AComb unitType ConsCall (pre "()", unitType) []
1 -> head xs
n -> let tys = map annExpr xs
tt = tupleType tys
ft = foldr FuncType tt tys
in AComb tt ConsCall (tupleCons n, ft) xs
string2TAFCY :: String -> TAExpr
string2TAFCY [] = AComb stringType ConsCall (pre "[]",stringType) []
string2TAFCY (c:cs) =
AComb stringType ConsCall
(pre ":", FuncType charType (FuncType stringType stringType))
[ALit charType (Charc c), string2TAFCY cs]
|