git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #195 from garyb/master

Improve pretty printing for row types

commitdfa5117e08ff65b003bcbe4c3f8a49e006dfde48 authorPhil Freeman <paf31@cantab.net> dateSun 16 Feb 2014, 11:06 (13 years ago) parent4afcadc9020386
2 files changed+7−4
src/Language/PureScript/Pretty/Types.hs+6−3 src/Language/PureScript/TypeChecker/Types.hs+1−1
src/Language/PureScript/Pretty/Types.hs+6−3
@@ -32,7 +32,7 @@ import Language.PureScript.Pretty.Common
3232typeLiterals :: Pattern () Type String
3333typeLiterals = mkPattern match
3434 where
35− match (Object row) = Just $ "{ " ++ prettyPrintType row ++ " }"
35+ match (Object row) = Just $ "{ " ++ prettyPrintObjectRow row ++ " }"
3636 match (TypeVar var) = Just var
3737 match (PrettyPrintArray ty) = Just $ "[" ++ prettyPrintType ty ++ "]"
3838 match ty@(TypeConstructor ctor) = Just $ show ctor
@@ -41,9 +41,12 @@ typeLiterals = mkPattern match
4141 match (ConstrainedType deps ty) = Just $ "(" ++ intercalate "," (map (\(pn, ty') -> show pn ++ " (" ++ prettyPrintType ty' ++ ")") deps) ++ ") => " ++ prettyPrintType ty
4242 match (SaturatedTypeSynonym name args) = Just $ show name ++ "<" ++ intercalate "," (map prettyPrintType args) ++ ">"
4343 match (ForAll ident ty _) = Just $ "forall " ++ ident ++ ". " ++ prettyPrintType ty
44− match REmpty = Just $ prettyPrintRow REmpty
45− match row@(RCons _ _ _) = Just $ prettyPrintRow row
44+ match REmpty = Just $ "()"
45+ match row@(RCons _ _ _) = Just $ '(' : prettyPrintRow row ++ ")"
4646 match _ = Nothing
47+ prettyPrintObjectRow REmpty = ""
48+ prettyPrintObjectRow row@(RCons _ _ _) = prettyPrintRow row
49+ prettyPrintObjectRow _ = error "Non-row type in Object"
4750
4851-- |
4952-- Generate a pretty-printed string representing a Row
src/Language/PureScript/TypeChecker/Types.hs+1−1
@@ -152,7 +152,7 @@ unifyRows r1 r2 =
152152 unifyRows' [] REmpty [] REmpty = return ()
153153 unifyRows' [] (TypeVar v1) [] (TypeVar v2) | v1 == v2 = return ()
154154 unifyRows' [] (Skolem s1 _) [] (Skolem s2 _) | s1 == s2 = return ()
155− unifyRows' sd3 r3 sd4 r4 = throwError $ "Cannot unify " ++ prettyPrintRow (rowFromList (sd3, r3)) ++ " with " ++ prettyPrintRow (rowFromList (sd4, r4)) ++ "."
155+ unifyRows' sd3 r3 sd4 r4 = throwError $ "Cannot unify (" ++ prettyPrintRow (rowFromList (sd3, r3)) ++ ") with (" ++ prettyPrintRow (rowFromList (sd4, r4)) ++ ")."
156156
157157-- |
158158-- Ensure type constructors are equal after canonicalization