on master help sign in
Add the 'Str' data constructor to Ast.hs. Makes type checking go much much much faster!
c00d017evancz
src/Ast.hs+2
@@ -1,3 +1,4 @@
1+
1module Ast where
2module Ast where
2
3
3data Pattern = PData String [Pattern] | PVar String | PAnything
4data Pattern = PData String [Pattern] | PVar String | PAnything
@@ -5,6 +6,7 @@ data Pattern = PData String [Pattern] | PVar String | PAnything
5
6
6data Expr = Number Int
7data Expr = Number Int
7 | Chr Char
8 | Chr Char
9+ | Str String
8 | Boolean Bool
10 | Boolean Bool
9 | Range Expr Expr
11 | Range Expr Expr
10 | Access Expr String
12 | Access Expr String
src/CompileToJS.hs+1
@@ -27,6 +27,7 @@ toJS expr =
27 Number n -> show n
27 Number n -> show n
28 Var x -> x
28 Var x -> x
29 Chr c -> show c
29 Chr c -> show c
30+ Str s -> toJS . list $ map Chr s
30 Boolean b -> if b then "true" else "false"
31 Boolean b -> if b then "true" else "false"
31 Range lo hi -> jsRange (toJS lo) (toJS hi)
32 Range lo hi -> jsRange (toJS lo) (toJS hi)
32 Access e lbl -> toJS e ++ "." ++ lbl
33 Access e lbl -> toJS e ++ "." ++ lbl
src/Types/Constrain.hs+3−10
@@ -3,6 +3,7 @@ module Constrain where
3
3
4import Ast
4import Ast
5import Types
5import Types
6+import Data.List (foldl')
6import qualified Data.Set as Set
7import qualified Data.Set as Set
7import qualified Data.Map as Map
8import qualified Data.Map as Map
8import Control.Monad (liftM,mapM)
9import Control.Monad (liftM,mapM)
@@ -60,7 +61,7 @@ inference (If e1 e2 e3) =
60 , Set.unions [c1,c2,c3, Set.fromList [ t1 :=: BoolT, t2 :=: t3 ] ]
61 , Set.unions [c1,c2,c3, Set.fromList [ t1 :=: BoolT, t2 :=: t3 ] ]
61 , t2 )
62 , t2 )
62
63
63−inference (Data name es) = inference $ foldl App (Var name) es
64+inference (Data name es) = inference $ foldl' App (Var name) es
64inference (Binop op e1 e2) = inference (Var op `App` e1 `App` e2)
65inference (Binop op e1 e2) = inference (Var op `App` e1 `App` e2)
65inference (Access (Var x) y) = inference . Var $ x ++ "." ++ y
66inference (Access (Var x) y) = inference . Var $ x ++ "." ++ y
66inference (Range e1 e2) = inference (Var "elmRange" `App` e1 `App` e2)
67inference (Range e1 e2) = inference (Var "elmRange" `App` e1 `App` e2)
@@ -69,16 +70,8 @@ inference other =
69 case other of
70 case other of
70 Number _ -> primitive IntT
71 Number _ -> primitive IntT
71 Chr _ -> primitive CharT
72 Chr _ -> primitive CharT
73+ Str _ -> primitive string
72 Boolean _ -> primitive BoolT
74 Boolean _ -> primitive BoolT
73 _ -> beta >>= primitive
75 _ -> beta >>= primitive
74
76
75primitive t = return (Map.empty, Set.empty, t)
77primitive t = return (Map.empty, Set.empty, t)
76−{--
77− Let x e1 e2 ->
78− do (a1,c1,t1) <- inference e1
79− (a2,c2,t2) <- inference e2
80− let ts = Map.findWithDefault (error "inference") x a
81− return ( unionA a1 $ Map.delete x a2
82− , Set.unions [ c1, c2, Set.fromList $ map (:<: t1) ts ]
83− , t2 )
84−--}