git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Support constraints without forall
3652252Phil Freeman
examples/passing/NakedConstraint.pursnew file+12
@@ -0,0 +1,12 @@
1+module Main where
2+
3+import Control.Monad.Eff.Console
4+
5+class Partial where
6+
7+data List a = Nil | Cons a (List a)
8+
9+head :: (Partial) => List Int -> Int
10+head (Cons x _) = x
11+
12+main = log "Done"
src/Language/PureScript/Parser/Types.hs+11−11
@@ -63,7 +63,7 @@ parseTypeConstructor = TypeConstructor <$> parseQualified properName
63
63
64parseForAll :: TokenParser Type
64parseForAll :: TokenParser Type
65parseForAll = mkForAll <$> (P.try (reserved "forall") *> P.many1 (indented *> identifier) <* indented <* dot)
65parseForAll = mkForAll <$> (P.try (reserved "forall") *> P.many1 (indented *> identifier) <* indented <* dot)
66− <*> parseConstrainedType
66+ <*> parseType
67
67
68-- |
68-- |
69-- Parse a type as it appears in e.g. a data constructor
69-- Parse a type as it appears in e.g. a data constructor
@@ -79,21 +79,21 @@ parseTypeAtom = indented *> P.choice (map P.try
79 , parseTypeConstructor
79 , parseTypeConstructor
80 , parseForAll
80 , parseForAll
81 , parens parseRow
81 , parens parseRow
82+ , parseConstrainedType
82− , parens parsePolyType ])
83+ , parens parsePolyType
84+ ])
83
85
84parseConstrainedType :: TokenParser Type
86parseConstrainedType :: TokenParser Type
85parseConstrainedType = do
87parseConstrainedType = do
86− constraints <- P.optionMaybe . P.try $ do
87− constraints <- parens . commaSep1 $ do
88+ constraints <- parens . commaSep1 $ do
88− className <- parseQualified properName
89+ className <- parseQualified properName
89− indented
90+ indented
90− ty <- P.many parseTypeAtom
91+ ty <- P.many parseTypeAtom
91− return (className, ty)
92+ return (className, ty)
92− _ <- rfatArrow
93+ _ <- rfatArrow
93− return constraints
94 indented
94 indented
95 ty <- parseType
95 ty <- parseType
96− return $ maybe ty (flip ConstrainedType ty) constraints
96+ return $ ConstrainedType constraints ty
97
97
98parseAnyType :: TokenParser Type
98parseAnyType :: TokenParser Type
99parseAnyType = P.buildExpressionParser operators (buildPostfixParser postfixTable parseTypeAtom) P.<?> "type"
99parseAnyType = P.buildExpressionParser operators (buildPostfixParser postfixTable parseTypeAtom) P.<?> "type"