summaryrefslogtreecommitdiff
path: root/prototypes
diff options
context:
space:
mode:
authorAndor Penzes <andor.penzes@gmail.com>2015-12-11 12:49:03 +0100
committerAndor Penzes <andor.penzes@gmail.com>2015-12-11 12:49:17 +0100
commit4aedddf785fb8df395b173715d5059aa14eb9cee (patch)
tree5c1bdc6056802b274aa8538a5df9ec98f86d7b59 /prototypes
parent24efa1fb04f4fdd9af910753f6cab3f412de2f25 (diff)
Data definitions with record syntax.
Diffstat (limited to 'prototypes')
-rw-r--r--prototypes/Infer.hs13
-rw-r--r--prototypes/tests/accept/data.lc18
-rw-r--r--prototypes/tests/reject/data.lc1
3 files changed, 31 insertions, 1 deletions
diff --git a/prototypes/Infer.hs b/prototypes/Infer.hs
index bee972b2..836cef48 100644
--- a/prototypes/Infer.hs
+++ b/prototypes/Infer.hs
@@ -1375,7 +1375,11 @@ parseStmt ns e =
1375 let mkConTy (_, ts') = foldr (uncurry SPi) (foldl SAppV (SGlobal x) $ downTo (length ts') $ length ts) ts' 1375 let mkConTy (_, ts') = foldr (uncurry SPi) (foldl SAppV (SGlobal x) $ downTo (length ts') $ length ts) ts'
1376 cs <- 1376 cs <-
1377 do keyword "where" *> localIndentation Ge (localAbsoluteIndentation $ many $ typedId' ns Nothing nps) 1377 do keyword "where" *> localIndentation Ge (localAbsoluteIndentation $ many $ typedId' ns Nothing nps)
1378 <|> do keyword "=" *> sepBy1 ((,) <$> (pure <$> lcIdents ns) <*> (mkConTy <$> telescope (typeNS ns) Nothing nps)) (keyword "|") 1378 <|> do keyword "=" *>
1379 sepBy1 ((,) <$> (pure <$> lcIdents ns)
1380 <*> ( braces (mkConTy <$> (telescopeDataFields (typeNS ns) nps))
1381 <|> (mkConTy <$> telescope (typeNS ns) Nothing nps)) )
1382 (keyword "|")
1379 <|> pure [] 1383 <|> pure []
1380 return $ pure $ Data x ts t $ concatMap (\(vs, t) -> (,) <$> vs <*> pure t) cs 1384 return $ pure $ Data x ts t $ concatMap (\(vs, t) -> (,) <$> vs <*> pure t) cs
1381 <|> do (vs, t) <- try $ typedId' ns Nothing [] 1385 <|> do (vs, t) <- try $ typedId' ns Nothing []
@@ -1404,6 +1408,13 @@ parseStmt ns e =
1404 return $ mkLets' ge dcls 1408 return $ mkLets' ge dcls
1405 return $ pure $ FunAlt n ts gu $ f rhs 1409 return $ pure $ FunAlt n ts gu $ f rhs
1406 <|> pure . uncurry ValueDef <$> valueDef ns e 1410 <|> pure . uncurry ValueDef <$> valueDef ns e
1411 where
1412 telescopeDataFields ns vs = option (vs, []) $ do
1413 (x, vt) <- do name <- var (expNS ns)
1414 operator "::"
1415 term <- parseTerm ns PrecAtom vs
1416 return (name, (Visible, term))
1417 (id *** (vt:)) <$> (comma *> telescopeDataFields ns (x: vs) <|> pure (vs, []))
1407 1418
1408type DBNames = [SName] -- De Bruijn variable names 1419type DBNames = [SName] -- De Bruijn variable names
1409 1420
diff --git a/prototypes/tests/accept/data.lc b/prototypes/tests/accept/data.lc
new file mode 100644
index 00000000..60731eb8
--- /dev/null
+++ b/prototypes/tests/accept/data.lc
@@ -0,0 +1,18 @@
1data Data0 = Data0
2
3data Data1 a b c = Data1 a b c
4
5data Data2 = Data21 Int
6 | Data22 { x :: Int, y::Int }
7 | Data23 { x :: Int }
8 | Data24 { }
9
10data Data5 a5 b5 c5 = Data51 { a5::a5}
11 | Data52 { a5::a5, b5::b5, c5::c5 }
12 | Data53 Int a5 Float b5 c5
13
14{-
15f (Data41 {}) = 5
16f (Data42 {c4=c}) = c
17f d = a4 d
18-}
diff --git a/prototypes/tests/reject/data.lc b/prototypes/tests/reject/data.lc
new file mode 100644
index 00000000..4f609a33
--- /dev/null
+++ b/prototypes/tests/reject/data.lc
@@ -0,0 +1 @@
data Data1 = Data1 a b c