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

Support constraints without forall

commit77a6451575ed6becafbbdf8b0de87c12ae5d3ffd authorGary Burgess <gary.burgess@gmail.com> dateFri 11 Sep 2015, 10:54 (11 years ago) parent56944213652252
2 files changed+23−11
examples/passing/NakedConstraint.purs+12 src/Language/PureScript/Parser/Types.hs+11−11
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
6363
6464parseForAll :: TokenParser Type
6565parseForAll = mkForAll <$> (P.try (reserved "forall") *> P.many1 (indented *> identifier) <* indented <* dot)
66− <*> parseConstrainedType
66+ <*> parseType
6767
6868-- |
6969-- Parse a type as it appears in e.g. a data constructor
@@ -79,21 +79,21 @@ parseTypeAtom = indented *> P.choice (map P.try
7979 , parseTypeConstructor
8080 , parseForAll
8181 , parens parseRow
82− , parens parsePolyType ])
82+ , parseConstrainedType
83+ , parens parsePolyType
84+ ])
8385
8486parseConstrainedType :: TokenParser Type
8587parseConstrainedType = do
86− constraints <- P.optionMaybe . P.try $ do
87− constraints <- parens . commaSep1 $ do
88− className <- parseQualified properName
89− indented
90− ty <- P.many parseTypeAtom
91− return (className, ty)
92− _ <- rfatArrow
93− return constraints
88+ constraints <- parens . commaSep1 $ do
89+ className <- parseQualified properName
90+ indented
91+ ty <- P.many parseTypeAtom
92+ return (className, ty)
93+ _ <- rfatArrow
9494 indented
9595 ty <- parseType
96− return $ maybe ty (flip ConstrainedType ty) constraints
96+ return $ ConstrainedType constraints ty
9797
9898parseAnyType :: TokenParser Type
9999parseAnyType = P.buildExpressionParser operators (buildPostfixParser postfixTable parseTypeAtom) P.<?> "type"