Commit 5b50f0a5 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel
Browse files

Allow to use all naturals as set for constants

Same as the parent commit: Allows to use N (or ℕ) as set.
parent 9937c6cf
......@@ -54,6 +54,7 @@ newtype Product a = Product (NonEmpty (Factor a))
data ConstSet
= IntSet
| NatSet
| ExplicitSet (Vector Text)
deriving (Show, Eq)
......@@ -98,6 +99,7 @@ parseFactorExpr inner = (Const <$> parseConstExpr) <|> (parseIdOrExp inner)
parseConstExpr :: MonadParser m => m ConstSet
parseConstExpr =
((L.symbol "Z" <|> L.symbol "ℤ") >> return IntSet) <|>
((L.symbol "N" <|> L.symbol "ℕ") >> return NatSet) <|>
((ExplicitSet . V.fromList) <$> (L.braces (L.name `sepBy` L.comma)))
parseIdOrExp :: MonadParser m => m a -> m (Factor a)
......@@ -227,6 +229,9 @@ parseFactor (Const (ExplicitSet names)) = do
parseFactor (Const IntSet) = do
x <- L.signed L.decimal
return (ConstValue x, Nothing) -- same here
parseFactor (Const NatSet) = do
x <- L.decimal
return (ConstValue x, Nothing) -- and here
parseFactor (Identity inner) = do
successor <- inner
return (IdValue (), Just [(successor, 0)])
......
......@@ -138,6 +138,10 @@ functorExpressionSpec = describe "functorExpression" $ do
p "Z" `shouldParse` (Functor 1 (mkPoly [[Const IntSet]]))
p "ℤ" `shouldParse` (Functor 1 (mkPoly [[Const IntSet]]))
it "allows to use naturals as set for constants" $ do
p "N" `shouldParse` (Functor 1 (mkPoly [[Const NatSet]]))
p "ℕ" `shouldParse` (Functor 1 (mkPoly [[Const NatSet]]))
data SomeFunctor a where
SomeFunctor :: (Eq1 f, Typeable f, Show1 f) => f a -> SomeFunctor a
......@@ -261,6 +265,14 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
morphp (mkPoly [[Const IntSet]]) "x: -3\ny:-77" `shouldParse`
(encoding [(1, mkVal 0 [ConstValue (-3)]), (1, mkVal 0 [ConstValue (-77)])] [])
it "allows positive numbers as constants for naturls set" $ do
morphp (mkPoly [[Const NatSet]]) "x: 5\ny:30" `shouldParse`
(encoding [(1, mkVal 0 [ConstValue 5]), (1, mkVal 0 [ConstValue 30])] [])
it "doesn't allow negative numbers as constants for naturls set" $ do
morphp (mkPoly [[Const NatSet]]) `shouldFailOn` "x: -35\ny:-77"
refineSpec :: Spec
refineSpec = describe "refining" $ do
let morphp fexpr input = snd <$> parseMorphisms (Functor 1 fexpr) "" input
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment