on master help sign in
Overload literal numbers without a decimal point to be either Ints or Floats
commitd456cec5c80580ffc4bbd43cd2dd78a2022d7415 authorEvan Czaplicki <info@elm-lang.org> dateThu 25 Jul 2013, 01:25 (13 years ago) parent82ca695
3 files changed+10−11
compiler/Type/Constrain/Expression.hs+1−1 compiler/Type/Constrain/Literal.hs+6−6 compiler/Type/Constrain/Pattern.hs+3−4
compiler/Type/Constrain/Expression.hs+1−1
@@ -52,7 +52,7 @@ constrain :: Env.Environment -> LExpr a b -> Type -> IO TypeConstraint
5252constrain env (L _ _ expr) tipe =
5353 let list t = TermN (App1 (Env.get env Env.types "_List") t) in
5454 case expr of
55− Literal lit -> return $ Literal.constrain env lit tipe
55+ Literal lit -> Literal.constrain env lit tipe
5656
5757 Var name -> return (name <? tipe)
5858
compiler/Type/Constrain/Literal.hs+6−6
@@ -8,12 +8,12 @@ import Type.Type
88import Type.Fragment
99import Type.Environment as Env
1010
11−constrain :: Environment -> Literal -> Type -> TypeConstraint
11+constrain :: Environment -> Literal -> Type -> IO TypeConstraint
1212constrain env literal tipe =
1313 let prim name = Env.get env Env.types name in
1414 case literal of
15− IntNum _ -> tipe === prim "Int"
16− FloatNum _ -> tipe === prim "Float"
17− Chr _ -> tipe === prim "Char"
18− Str _ -> tipe === TermN (App1 (prim "[]") (prim "Char"))
19− Boolean _ -> tipe === prim "Bool"
15+ IntNum _ -> fmap (\n -> tipe === VarN n) number
16+ FloatNum _ -> return $ tipe === prim "Float"
17+ Chr _ -> return $ tipe === prim "Char"
18+ Str _ -> return $ tipe === TermN (App1 (prim "[]") (prim "Char"))
19+ Boolean _ -> return $ tipe === prim "Bool"
compiler/Type/Constrain/Pattern.hs+3−4
@@ -20,10 +20,9 @@ constrain env pattern tipe =
2020 case pattern of
2121 PAnything -> return emptyFragment
2222
23− PLiteral lit ->
24− return $ emptyFragment {
25− typeConstraint = Literal.constrain env lit tipe
26− }
23+ PLiteral lit -> do
24+ c <- Literal.constrain env lit tipe
25+ return $ emptyFragment { typeConstraint = c }
2726
2827 PVar name -> do
2928 v <- flexibleVar