git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Empty data decls and empty type class decls
6410369Phil Freeman
examples/passing/EmptyDataDecls.pursnew file+20
@@ -0,0 +1,20 @@
1+module Main where
2+
3+import Prelude
4+import Data.Array
5+
6+data Z
7+data S n
8+
9+data Array n a = Array [a]
10+
11+nil :: forall a. Array Z a
12+nil = Array []
13+
14+cons :: forall a n. a -> Array n a -> Array (S n) a
15+cons x (Array xs) = Array $ x : xs
16+
17+main = let (Array xs) = cons 1 $ cons 2 $ cons 3 nil
18+ in if xs == [1, 2, 3]
19+ then Debug.Trace.trace "Done"
20+ else Control.Monad.Error.throwError "Failed"
examples/passing/EmptyTypeClass.pursnew file+18
@@ -0,0 +1,18 @@
1+module EmptyTypeClass where
2+
3+class Partial
4+
5+head :: forall a. (Partial) => [a] -> a
6+head (x:xs) = x
7+
8+module AllowPartialFns where
9+
10+instance EmptyTypeClass.Partial
11+
12+module Main where
13+
14+import Prelude
15+import AllowPartialFns
16+import EmptyTypeClass
17+
18+main = Debug.Trace.trace $ head ["Done"]
src/Language/PureScript/Parser/Declarations.hs+11−8
@@ -36,8 +36,9 @@ parseDataDeclaration = do
36 reserved "data"
36 reserved "data"
37 name <- indented *> properName
37 name <- indented *> properName
38 tyArgs <- many (indented *> identifier)
38 tyArgs <- many (indented *> identifier)
39+ ctors <- P.option [] $ do
39− _ <- lexeme $ indented *> P.char '='
40+ _ <- lexeme $ indented *> P.char '='
40− ctors <- sepBy1 ((,) <$> properName <*> P.many (indented *> parseTypeAtom)) pipe
41+ sepBy1 ((,) <$> properName <*> P.many (indented *> parseTypeAtom)) pipe
41 return $ DataDeclaration name tyArgs ctors
42 return $ DataDeclaration name tyArgs ctors
42
43
43parseTypeDeclaration :: P.Parsec String ParseState Declaration
44parseTypeDeclaration :: P.Parsec String ParseState Declaration
@@ -94,9 +95,10 @@ parseTypeClassDeclaration :: P.Parsec String ParseState Declaration
94parseTypeClassDeclaration = do
95parseTypeClassDeclaration = do
95 reserved "class"
96 reserved "class"
96 className <- indented *> properName
97 className <- indented *> properName
97− idents <- indented *> P.many identifier
98+ idents <- P.many (indented *> identifier)
99+ members <- P.option [] . P.try $ do
98− indented *> reserved "where"
100+ indented *> reserved "where"
99− members <- mark (P.many (same *> parseTypeDeclaration))
101+ mark (P.many (same *> parseTypeDeclaration))
100 return $ TypeClassDeclaration className idents members
102 return $ TypeClassDeclaration className idents members
101
103
102parseTypeInstanceDeclaration :: P.Parsec String ParseState Declaration
104parseTypeInstanceDeclaration :: P.Parsec String ParseState Declaration
@@ -108,9 +110,10 @@ parseTypeInstanceDeclaration = do
108 reservedOp "=>"
110 reservedOp "=>"
109 return deps
111 return deps
110 className <- indented *> parseQualified properName
112 className <- indented *> parseQualified properName
111− ty <- indented *> P.many parseTypeAtom
113+ ty <- P.many (indented *> parseTypeAtom)
114+ members <- P.option [] . P.try $ do
112− indented *> reserved "where"
115+ indented *> reserved "where"
113− members <- mark (P.many (same *> parseValueDeclaration))
116+ mark (P.many (same *> parseValueDeclaration))
114 return $ TypeInstanceDeclaration (fromMaybe [] deps) className ty members
117 return $ TypeInstanceDeclaration (fromMaybe [] deps) className ty members
115
118
116-- |
119-- |