-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hs
45 lines (40 loc) · 1.1 KB
/
Main.hs
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
--------------------------------------------------------------------------------
-- Free type variables
--
-- Main program
--
-- Pepe Gallardo, 2017
--
--------------------------------------------------------------------------------
import qualified Assumptions
import Expr
import ExprParser
import Lex
import Mon
import Type
import TypeInference
import qualified TypeVarName
import qualified TypeVarName
assumptions :: Assumptions.Assumptions
assumptions =
Assumptions.addPoly lxNil (Forall [alphaName] listAlpha) $
Assumptions.addPoly lxCons (Forall [alphaName] $ alpha *-> (listAlpha *-> listAlpha)) $
Assumptions.empty
where
alphaName = TypeVarName.fromChar 'a'
alpha = TypeVar alphaName
listAlpha = listType alpha
typeOfString :: String -> Type
typeOfString str = runMon assumptions $ do
expr <- parseExpr str
typeOf expr
main :: IO ()
main =
mapM_ (\ex -> do putStr ex; putStr " :: "; print (typeOfString ex)) examples
examples =
[ "\\x -> x"
, "\\f x -> (f, f x, f (f x))"
, "\\x -> [x, x]"
, "let f = \\x -> x in (f, f True, f 1)"
, "\\f x -> if True then f 2 else f x"
]