on master help sign in
Fix how types are converted to strings. This actually fixes some bugs that come from generating docs.json, which led to incorrect types being used in the compiler.
commit530bc6e2b988ea1929c5be2e39050cf648757a23 authorevancz <info@elm-lang.org> dateTue 9 Apr 2013, 22:12 (14 years ago) parent7d03f69
2 files changed+6−7
compiler/Gen/CompileToJS.hs+1−1 compiler/Types/Types.hs+5−6
compiler/Gen/CompileToJS.hs+1−1
@@ -315,7 +315,7 @@ clauseToJS span var (Clause name vars e) = do
315315jsNil = "_L.Nil"
316316jsCons e1 e2 = "_L.Cons(" ++ e1 ++ "," ++ e2 ++ ")"
317317jsRange e1 e2 = "_L.range" ++ parens (e1 ++ "," ++ e2)
318−jsCompare e1 e2 op = parens ("_N.compare(" ++ e1 ++ "," ++ e2 ++ ").ctor" ++ op)
318+jsCompare e1 e2 op = parens ("_N.cmp(" ++ e1 ++ "," ++ e2 ++ ").ctor" ++ op)
319319
320320binop (o:p) e1 e2
321321 | isAlpha o || '_' == o = (o:p) ++ parens e1 ++ parens e2
compiler/Types/Types.hs+5−6
@@ -68,19 +68,18 @@ parens = ("("++) . (++")")
6868
6969instance Show Type where
7070 show t =
71− let show' t = case t of { LambdaT _ _ -> parens (show t) ; _ -> show t }
71+ let addParens (c:cs) =
72+ if notElem ' ' cs || c == '(' then c:cs else parens (c:cs)
7273 in case t of
73− LambdaT t1@(LambdaT _ _) t2 -> show' t1 ++ " -> " ++ show t2
74+ LambdaT t1@(LambdaT _ _) t2 -> parens (show t1) ++ " -> " ++ show t2
7475 LambdaT t1 t2 -> show t1 ++ " -> " ++ show t2
7576 VarT x -> 't' : show x
76− --ADT "List" [ADT "Char" []] -> "String"
77+ ADT "List" [ADT "Char" []] -> "String"
7778 ADT "List" [tipe] -> "[" ++ show tipe ++ "]"
7879 ADT name cs ->
7980 if isTupleString name
8081 then parens . intercalate "," $ map show cs
81− else case cs of
82− [] -> name
83− _ -> name ++ " " ++ unwords (map show cs)
82+ else name ++ concatMap ((' ':) . addParens . show) cs
8483 Super ts -> "{" ++ (intercalate "," . map show $ Set.toList ts) ++ "}"
8584 EmptyRecord -> "{}"
8685 RecordT fs t ->