on master help sign in
Add the 'Str' data constructor to Ast.hs. Makes type checking go much much much faster!
commitc00d0171a8282b5aca3d31cc3ddda193bbf17011 authorevancz <info@elm-lang.org> dateSun 20 May 2012, 01:11 (14 years ago) parent5b49500
3 files changed+6−10
src/Ast.hs+2 src/CompileToJS.hs+1 src/Types/Constrain.hs+3−10
src/Ast.hs+2
@@ -1,3 +1,4 @@
1+
12module Ast where
23
34data Pattern = PData String [Pattern] | PVar String | PAnything
@@ -5,6 +6,7 @@ data Pattern = PData String [Pattern] | PVar String | PAnything
56
67data Expr = Number Int
78 | Chr Char
9+ | Str String
810 | Boolean Bool
911 | Range Expr Expr
1012 | Access Expr String
src/CompileToJS.hs+1
@@ -27,6 +27,7 @@ toJS expr =
2727 Number n -> show n
2828 Var x -> x
2929 Chr c -> show c
30+ Str s -> toJS . list $ map Chr s
3031 Boolean b -> if b then "true" else "false"
3132 Range lo hi -> jsRange (toJS lo) (toJS hi)
3233 Access e lbl -> toJS e ++ "." ++ lbl
src/Types/Constrain.hs+3−10
@@ -3,6 +3,7 @@ module Constrain where
33
44import Ast
55import Types
6+import Data.List (foldl')
67import qualified Data.Set as Set
78import qualified Data.Map as Map
89import Control.Monad (liftM,mapM)
@@ -60,7 +61,7 @@ inference (If e1 e2 e3) =
6061 , Set.unions [c1,c2,c3, Set.fromList [ t1 :=: BoolT, t2 :=: t3 ] ]
6162 , t2 )
6263
63−inference (Data name es) = inference $ foldl App (Var name) es
64+inference (Data name es) = inference $ foldl' App (Var name) es
6465inference (Binop op e1 e2) = inference (Var op `App` e1 `App` e2)
6566inference (Access (Var x) y) = inference . Var $ x ++ "." ++ y
6667inference (Range e1 e2) = inference (Var "elmRange" `App` e1 `App` e2)
@@ -69,16 +70,8 @@ inference other =
6970 case other of
7071 Number _ -> primitive IntT
7172 Chr _ -> primitive CharT
73+ Str _ -> primitive string
7274 Boolean _ -> primitive BoolT
7375 _ -> beta >>= primitive
7476
7577primitive 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−--}