Commit 92a63e1b authored by Bastian Kauschke's avatar Bastian Kauschke

remove Printable

parent 6760be29
......@@ -18,8 +18,8 @@ import Copar.FunctorExpression.Sorts
import Copar.FunctorExpression.Type
import Copar.FunctorExpression.Parser
import Copar.Functors.Polynomial
import Copar.Functors.SomeFunctor (someFunctorExprParser)
import Copar.Functors
import Copar.FunctorDescription
benchmarks :: Benchmark
benchmarks = bgroup "Morphism Parser"
......@@ -38,7 +38,7 @@ benchIdentity = bgroup "Identity" $
benchMarkov :: Benchmark
benchMarkov = bgroup "Ax(R^X)" $
let
functors = map dynFunctorExprParser registeredFunctors
functors = map someFunctorExprParser registeredFunctors
Right f = annotateSorts <$> parseFunctorExpression functors "" "{a,b,c,d,e}x(R^X)"
in
[ benchParser "simple" f
......
......@@ -56,7 +56,6 @@ library
, Copar.Algorithm.Split
, Copar.FunctorExpression.Type
, Copar.FunctorExpression.Parser
, Copar.FunctorExpression.Printable
, Copar.FunctorExpression.Sorts
, Copar.FunctorExpression.Desorting
, Copar.FunctorExpression.Transform
......
......@@ -22,16 +22,12 @@ data Pair a = Pair a a
$(deriveShow1 ''Pair)
instance Printable Distribution where
printMe cfg (Pair lhs rhs) = withName cfg "Pair" <> lhs <> " x " <> rhs
pair :: FunctorDescription Pair
pair = FunctorDescription
{ name = "Pair"
, syntaxExample = "{f, n} x PX"
, description = Just "A pair of functors"
, functorExprParser = pairp
}
instance FunctorDescription Pair where
name = "Pair"
syntaxExample = "{f, n} x PX"
description = Just "A pair of functors"
functorExprParser = pairp
functorExprPrinter cfg (Pair lhs rhs) = withName cfg "Pair" <> lhs <> " x " <> rhs
pairp :: FunctorParser Pair
pairp = FunctorParser $ \inner ->
......
......@@ -6,8 +6,8 @@ module Copar.FunctorDescription
( DynFunctorDescription(..)
, FunctorParser(..)
, FunctorDescription(..)
, PrintConfig(..)
, Suitable
, ToDynFunctorDescription(..)
, formatFunctorDescription
, formatFunctorDescriptions
, dynPrecedence
......@@ -24,12 +24,12 @@ import Data.Text.Prettyprint ( Doc
, AnsiStyle
)
import qualified Data.Text.Prettyprint as Doc
import qualified Data.Text.Lazy.Builder as Build
import Data.Proxy
import Type.Reflection
import Copar.FunctorExpression.Printable
import Copar.FunctorExpression.Parser
import Copar.RefinementInterface
import Copar.Coalgebra.Parser.Class
......@@ -38,7 +38,6 @@ import Copar.PrettyShow
type Suitable f
= ( RefinementInterface f
, ParseMorphism f
, Printable f
, Eq1 f
, Functor f
, FunctorDescription f
......@@ -57,13 +56,12 @@ class FunctorDescription f where
description :: Maybe (Doc AnsiStyle)
precedence :: Int
functorExprParser :: FunctorParser f
functorExprPrinter :: PrintConfig -> f Build.Builder -> Build.Builder
dynFunctorDescription :: forall f. Suitable f => DynFunctorDescription
dynFunctorDescription = DynFunctorDescription (Proxy :: Proxy f)
class ToDynFunctorDescription f where
toDynFunctorDescription :: f a -> DynFunctorDescription
data PrintConfig = PrintConfig { withName :: Build.Builder -> Build.Builder }
data DynFunctorDescription where
DynFunctorDescription :: Suitable f => Proxy f -> DynFunctorDescription
......
module Copar.FunctorExpression.Printable
( Printable (..)
, PrintConfig (..)
, printTree
, defaultPrintConfig
) where
import Data.Text.Lazy.Builder as Build
-- | Print the required skeleton for the current scope.
--
-- The current scope has already been popped of the stack.
printSkeleton :: [a] -> [[a]] -> Build.Builder
printSkeleton h xs =
foldl (\str e -> (if null e then " " else "│ ") <> str)
(if null h then "└ " else "├ ")
xs
printTree :: (a -> ([(Build.Builder, a)], Build.Builder)) -> a -> Build.Builder
printTree f head =
let (children, functor) = f head
in functor <> printInner f [children]
printInner :: (a -> ([(Build.Builder, a)], Build.Builder)) -> [[(Build.Builder, a)]] -> Build.Builder
printInner f (((scope, v):h):rs) =
"\n" <> printSkeleton h rs <> scope <> ": "
<> functor <> (printInner f (children:h:rs))
where
(children, functor) = f v
printInner f ([]:rs) = printInner f rs
printInner _ [] = mempty
data PrintConfig = PrintConfig { withName :: Build.Builder -> Build.Builder }
defaultPrintConfig :: PrintConfig
defaultPrintConfig = PrintConfig {
withName = \name -> name <> " "
}
class Printable f where
printMe :: PrintConfig -> f Build.Builder -> Build.Builder
module Copar.FunctorPrinter (printFunctor, printParseableFunctor, Printable) where
module Copar.FunctorPrinter (printFunctor, printParseableFunctor) where
import Data.Text as T
import Data.Text.Lazy as Lazy
import Data.Text.Lazy.Builder as Build
import qualified Data.Text as T
import qualified Data.Text.Lazy as Lazy
import qualified Data.Text.Lazy.Builder as Build
import Copar.FunctorExpression.Printable
import Copar.FunctorExpression.Sorts (Sort, formatSortAsScope)
import Copar.FunctorExpression.Type (FunctorExpression (..))
import Copar.FunctorDescription
import Copar.Functors.SomeFunctor
printFunctor :: (Printable f, Foldable f, Functor f) => FunctorExpression f Sort -> T.Text
printFunctor :: FunctorExpression SomeFunctor Sort -> T.Text
printFunctor (Functor _ f') = Lazy.toStrict (Build.toLazyText (printTree inner f'))
printFunctor Variable = "Variable X"
inner :: (Printable f, Foldable f, Functor f)
=> f (FunctorExpression f Sort)
inner :: SomeFunctor (FunctorExpression SomeFunctor Sort)
-- ([('sort, subfunctor)], functor)
-> ([(Build.Builder, f (FunctorExpression f Sort))], Build.Builder)
-> ([(Build.Builder, SomeFunctor (FunctorExpression SomeFunctor Sort))], Build.Builder)
inner f = (foldMap getChild f, print (fmap printChild f))
where
print = printMe PrintConfig { withName = \name -> name <> " " }
print = printSomeFunctorExpr PrintConfig { withName = \name -> name <> " " }
printChild Variable = "X"
printChild (Functor sort _) = formatSortAsScope sort
......@@ -27,21 +26,44 @@ inner f = (foldMap getChild f, print (fmap printChild f))
getChild Variable = []
getChild (Functor sort f') = [(formatSortAsScope sort, f')]
printParseableFunctor :: (ToDynFunctorDescription f, Printable f, Foldable f, Functor f) => FunctorExpression f Sort -> T.Text
printParseableFunctor :: FunctorExpression SomeFunctor Sort -> T.Text
printParseableFunctor (Functor _ f') = Lazy.toStrict (Build.toLazyText (print (fmap (printInner (functorPrecedence f')) f')))
where
print :: forall f. (Printable f) => f Build.Builder -> Build.Builder
print = printMe PrintConfig { withName = \_ -> "" }
print :: SomeFunctor Build.Builder -> Build.Builder
print = printSomeFunctorExpr PrintConfig { withName = \_ -> "" }
functorPrecedence :: ToDynFunctorDescription f => f a -> Int
functorPrecedence = dynPrecedence . toDynFunctorDescription
functorPrecedence :: SomeFunctor a -> Int
functorPrecedence = dynPrecedence . someFunctorDescription
printInner :: (ToDynFunctorDescription f, Printable f, Foldable f, Functor f) => Int -> FunctorExpression f Sort -> Build.Builder
printInner :: Int -> FunctorExpression SomeFunctor Sort -> Build.Builder
printInner _ Variable = "X"
printInner prec (Functor _ inner) =
let inner_prec = dynPrecedence (toDynFunctorDescription inner)
let inner_prec = dynPrecedence (someFunctorDescription inner)
in if inner_prec > prec
then print (fmap (printInner inner_prec) inner)
else "(" <> print (fmap (printInner inner_prec) inner) <> ")"
printParseableFunctor Variable = "X"
-- | Print the required skeleton for the current scope.
--
-- The current scope has already been popped of the stack.
printSkeleton :: [a] -> [[a]] -> Build.Builder
printSkeleton h xs =
foldl (\str e -> (if null e then " " else "│ ") <> str)
(if null h then "└ " else "├ ")
xs
printTree :: (a -> ([(Build.Builder, a)], Build.Builder)) -> a -> Build.Builder
printTree f head =
let (children, functor) = f head
in functor <> printInner f [children]
printInner :: (a -> ([(Build.Builder, a)], Build.Builder)) -> [[(Build.Builder, a)]] -> Build.Builder
printInner f (((scope, v):h):rs) =
"\n" <> printSkeleton h rs <> scope <> ": "
<> functor <> (printInner f (children:h:rs))
where
(children, functor) = f v
printInner f ([]:rs) = printInner f rs
printInner _ [] = mempty
\ No newline at end of file
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE UndecidableInstances #-}
......@@ -45,11 +46,11 @@ import Data.Text ( Text )
import Text.Megaparsec
import Copar.Coalgebra.Parser
import qualified Copar.Parser.Lexer as L
import qualified Copar.Parser.Lexer as L
import Copar.RefinementInterface
import Copar.Functors.Polynomial hiding ( PolyF1(..) )
import qualified Copar.Functors.SomeFunctor as SF
import Copar.FunctorExpression.Type
import Copar.FunctorExpression.Printable
import Copar.FunctorDescription
import Copar.Parser.Types
......@@ -66,23 +67,23 @@ $(deriveEq1 ''Inner)
newtype AbsorbingPolynomial f a = AbsorbingPolynomial (Polynomial (Inner f a))
deriving (Functor, Foldable, Traversable)
instance FunctorDescription (AbsorbingPolynomial f) where
instance FunctorDescription (AbsorbingPolynomial SF.SomeFunctor) where
name = "AbsorbingPolynomial"
syntaxExample = "2xX + X^3"
description = Nothing -- AbsorbingPolynomial is not relevant for users
precedence = 10
functorExprParser = undefined -- It is not possible to parse an AbsorbnigPolynomial directly
instance (ToDynFunctorDescription f, Printable f) => Printable (AbsorbingPolynomial f) where
printMe cfg (AbsorbingPolynomial poly) =
let name = withName cfg "AbsorbingPolynomial"
functorExprPrinter cfg (AbsorbingPolynomial poly) =
let name = withName cfg "AbsorbingPolynomial"
in name <> printPolynomial cfg ((\case
Direct a -> a
-- We want to always print the surrounding braces in case functor names
-- are printed.
Absorbed inner -> if dynPrecedence (toDynFunctorDescription inner) > 10 && name == mempty
then printMe cfg inner
else "(" <> printMe cfg inner <> ")"
Absorbed inner ->
if dynPrecedence (SF.someFunctorDescription inner) > 10 && name == mempty
then SF.printSomeFunctorExpr cfg inner
else "(" <> SF.printSomeFunctorExpr cfg inner <> ")"
) <$> poly)
$(deriveShow1 ''AbsorbingPolynomial)
......
......@@ -24,7 +24,6 @@ import Data.Text.Prettyprint ((<+>))
import Copar.RefinementInterface
import qualified Copar.Parser.Lexer as L
import Copar.FunctorExpression.Parser
import Copar.FunctorExpression.Printable
import Copar.Coalgebra.Parser
import Copar.Functors.GroupValued
import Copar.FunctorDescription
......@@ -32,9 +31,6 @@ import Copar.FunctorDescription
newtype Bag a = Bag a
deriving (Functor,Foldable,Traversable)
instance Printable Bag where
printMe cfg (Bag x) = withName cfg "Bag" <> "B" <> x
instance FunctorDescription Bag where
name = "Bag"
syntaxExample = "BX | ƁX"
......@@ -42,6 +38,8 @@ instance FunctorDescription Bag where
precedence = 40
functorExprParser = prefix ((L.symbol "B" <|> L.symbol "Ɓ") >> pure Bag)
functorExprPrinter cfg (Bag x) = withName cfg "Bag" <> "B" <> x
bagHelp :: Doc.Doc Doc.AnsiStyle
bagHelp =
Doc.reflow "This is like the Powerset functor, except that states can have \
......
......@@ -19,7 +19,6 @@ import Data.Float.Utils (EqDouble)
import Copar.Coalgebra.Parser
import Copar.FunctorDescription
import Copar.FunctorExpression.Parser
import Copar.FunctorExpression.Printable
import Copar.Functors.GroupValued
import qualified Copar.Parser.Lexer as L
import Copar.RefinementInterface
......@@ -28,9 +27,6 @@ import Copar.RefinementInterface
newtype Distribution x = Distribution x
deriving (Functor, Foldable, Traversable)
instance Printable Distribution where
printMe cfg (Distribution x) = withName cfg "Distribution" <> "D" <> x
instance FunctorDescription Distribution where
name = "Distribution"
syntaxExample = "DX | ƊX"
......@@ -39,6 +35,8 @@ instance FunctorDescription Distribution where
functorExprParser = prefix ((L.symbol "D" <|> L.symbol "Ɗ")
>> pure Distribution)
functorExprPrinter cfg (Distribution x) = withName cfg "Distribution" <> "D" <> x
distHelp :: Doc.Doc Doc.AnsiStyle
distHelp =
Doc.reflow "Coalgebras for the distribution functor correspond to markov \
......
......@@ -37,7 +37,6 @@ import qualified Data.Vector.Utils as V
import Copar.RefinementInterface
import Copar.Coalgebra.Parser
import Copar.FunctorExpression.Parser
import Copar.FunctorExpression.Printable
import qualified Copar.Parser.Lexer as L
import Copar.Parser.Types
import Copar.FunctorDescription
......@@ -54,19 +53,6 @@ deriving instance Traversable (GroupValued m)
$(deriveShow1 ''GroupValued)
instance Printable (GroupValued Int) where
printMe cfg (GroupValued x) = withName cfg "Integer-valued" <> "Z^" <> x
instance Printable (GroupValued EqDouble) where
printMe cfg (GroupValued x) = withName cfg "Real-valued" <> "R^" <> x
instance Printable (GroupValued OrderedComplex) where
printMe cfg (GroupValued x) = withName cfg "Complex-valued" <> "C^" <> x
instance Printable (GroupValued (Ratio Int)) where
printMe cfg (GroupValued x) = withName cfg "Rational-valued" <> "Q^" <> x
type IntValued = GroupValued Int
instance FunctorDescription (GroupValued Int) where
......@@ -76,6 +62,7 @@ instance FunctorDescription (GroupValued Int) where
precedence = 150
functorExprParser =
prefix ((L.symbol "Z" <|> L.symbol "ℤ") >> L.symbol "^" >> pure GroupValued)
functorExprPrinter cfg (GroupValued x) = withName cfg "Integer-valued" <> "Z^" <> x
intHelp :: Doc.Doc Doc.AnsiStyle
intHelp =
......@@ -95,6 +82,7 @@ instance FunctorDescription (GroupValued EqDouble) where
precedence = 140
functorExprParser = prefix
((L.symbol "R" <|> L.symbol "ℝ") >> L.symbol "^" >> pure GroupValued)
functorExprPrinter cfg (GroupValued x) = withName cfg "Real-valued" <> "R^" <> x
realHelp :: Doc.Doc Doc.AnsiStyle
realHelp =
......@@ -114,6 +102,7 @@ instance FunctorDescription (GroupValued (Ratio Int)) where
precedence = 120
functorExprParser = prefix
((L.symbol "Q" <|> L.symbol "ℚ") >> L.symbol "^" >> pure GroupValued)
functorExprPrinter cfg (GroupValued x) = withName cfg "Rational-valued" <> "Q^" <> x
rationalHelp :: Doc.Doc Doc.AnsiStyle
rationalHelp =
......@@ -143,6 +132,7 @@ instance FunctorDescription (GroupValued OrderedComplex) where
precedence = 130
functorExprParser = prefix
((L.symbol "C" <|> L.symbol "ℂ") >> L.symbol "^" >> pure GroupValued)
functorExprPrinter cfg (GroupValued x) = withName cfg "Complex-valued" <> "C^" <> x
complexHelp :: Doc.Doc Doc.AnsiStyle
complexHelp =
......
......@@ -32,13 +32,13 @@ import Text.Megaparsec
import qualified Data.Text.Prettyprint as Doc
import Data.Text.Prettyprint ( (<+>) )
import Data.Text ( Text )
import qualified Data.Text.Lazy.Builder as Build
import qualified Data.Vector.Utils as V
import Copar.RefinementInterface
import Copar.FunctorDescription
import qualified Copar.Parser.Lexer as L
import Copar.FunctorExpression.Parser
import Copar.FunctorExpression.Printable
import Copar.Coalgebra.Parser
import Data.Float.Utils ( MaxDouble(..)
, MinDouble(..)
......@@ -53,25 +53,6 @@ import Data.Proxy
newtype SlowMonoidValued m a = SlowMonoidValued a
-- TODO Remove Printable in favor of FunctorDescription
instance Printable (SlowMonoidValued (Max Int)) where
printMe cfg (SlowMonoidValued x) = withName cfg "Max-valued" <> "(Z, max)^" <> x
instance Printable (SlowMonoidValued (Min Int)) where
printMe cfg (SlowMonoidValued x) = withName cfg "Min-valued" <> "(Z, min)^" <> x
instance Printable (SlowMonoidValued MaxDouble) where
printMe cfg (SlowMonoidValued x) = withName cfg "Max-valued" <> "(R, max)^" <> x
instance Printable (SlowMonoidValued MinDouble) where
printMe cfg (SlowMonoidValued x) = withName cfg "Min-valued" <> "(R, min)^" <> x
instance Printable (SlowMonoidValued (BitAnd Word64)) where
printMe cfg (SlowMonoidValued x) = withName cfg "BitAnd-valued" <> "(Word, and)^" <> x
instance Printable (SlowMonoidValued (BitOr Word64)) where
printMe cfg (SlowMonoidValued x) = withName cfg "BitOr-valued" <> "(Word, or)^" <> x
instance Eq1 (SlowMonoidValued m) where
liftEq f (SlowMonoidValued a1) (SlowMonoidValued a2) = f a1 a2
......@@ -112,6 +93,11 @@ instance MonoidValuedDescription m => FunctorDescription (SlowMonoidValued m) wh
>> pure SlowMonoidValued
)
functorExprPrinter cfg (SlowMonoidValued x) =
withName cfg (Build.fromText (name @(SlowMonoidValued m))) <>
"(" <> Build.fromText (head (mvSet @m)) <> ", " <> Build.fromText (mvOperation @m) <> ")^"
<> x
functorSyntax :: Text -> Text -> Text
functorSyntax s o = "(" <> s <> ", " <> o <> ")^X"
......
......@@ -55,7 +55,6 @@ import qualified Copar.Parser.Lexer as L
import Copar.Parser.Types
import Copar.RefinementInterface
import Copar.FunctorExpression.Parser
import Copar.FunctorExpression.Printable
import Copar.FunctorDescription
......@@ -94,10 +93,6 @@ $(deriveEq1 ''Polynomial)
$(deriveShow1 ''Factor)
$(deriveShow1 ''Polynomial)
instance Printable Polynomial where
printMe cfg poly = withName cfg "Polynomial" <> printPolynomial cfg poly
printPolynomial :: PrintConfig -> Polynomial Build.Builder -> Build.Builder
printPolynomial cfg (Polynomial (Sum (prods))) = fold (NonEmpty.intersperse " + " (fmap (printProduct cfg) prods))
......@@ -148,6 +143,7 @@ instance FunctorDescription Polynomial where
description = Just polynomialHelp
precedence = 10
functorExprParser = polynomialp
functorExprPrinter cfg poly = withName cfg "Polynomial" <> printPolynomial cfg poly
polynomialHelp :: Doc.Doc Doc.AnsiStyle
polynomialHelp =
......
......@@ -25,7 +25,6 @@ import Data.Text.Prettyprint ((<+>))
import Copar.RefinementInterface
import qualified Copar.Parser.Lexer as L
import Copar.FunctorExpression.Parser
import Copar.FunctorExpression.Printable
import Copar.Coalgebra.Parser
import Copar.FunctorDescription
......@@ -35,9 +34,6 @@ newtype Powerset a = Powerset a
$(deriveShow1 ''Powerset)
$(deriveEq1 ''Powerset)
instance Printable Powerset where
printMe cfg (Powerset x) = withName cfg "Powerset" <> "P" <> x
instance FunctorDescription Powerset where
name = "Powerset"
syntaxExample = "PX | ƤX"
......@@ -45,6 +41,7 @@ instance FunctorDescription Powerset where
precedence = 50
functorExprParser =
prefix ((L.symbol "P" <|> L.symbol "Ƥ") >> pure Powerset)
functorExprPrinter cfg (Powerset x) = withName cfg "Powerset" <> "P" <> x
powersetHelp :: Doc.Doc Doc.AnsiStyle
powersetHelp =
......
......@@ -11,7 +11,8 @@ module Copar.Functors.SomeFunctor
, Suitable
, transformInner
, someFunctorExprParser
, dynFunctorExprParser
, someFunctorDescription
, printSomeFunctorExpr
, SomeWeight(..)
, SomeLabel
, SomeF1
......@@ -32,9 +33,9 @@ import Data.Proxy
import Control.DeepSeq (NFData(..))
import qualified Data.Vector as V
import qualified Data.Text as T
import qualified Data.Text.Lazy.Builder as Build
import Copar.Coalgebra.Parser.Class
import Copar.FunctorExpression.Printable
import Copar.FunctorExpression.Parser
import Copar.PrettyShow
......@@ -51,11 +52,11 @@ data SomeFunctor a where
someFunctorExprParser :: DynFunctorDescription -> FunctorParser SomeFunctor
someFunctorExprParser (DynFunctorDescription (Proxy :: Proxy f)) = transParser SomeFunctor (functorExprParser @f)
instance ToDynFunctorDescription SomeFunctor where
toDynFunctorDescription (SomeFunctor (_ :: f a)) = DynFunctorDescription (Proxy :: Proxy f)
someFunctorDescription :: SomeFunctor a -> DynFunctorDescription
someFunctorDescription (SomeFunctor (_ :: f a)) = DynFunctorDescription (Proxy :: Proxy f)
dynFunctorExprParser :: DynFunctorDescription -> FunctorParser SomeFunctor
dynFunctorExprParser (DynFunctorDescription (Proxy :: Proxy f)) = transParser SomeFunctor (functorExprParser @f)
printSomeFunctorExpr :: PrintConfig -> SomeFunctor Build.Builder -> Build.Builder
printSomeFunctorExpr cfg (SomeFunctor x) = functorExprPrinter cfg x
deriving instance Functor SomeFunctor
deriving instance Foldable SomeFunctor
......@@ -77,9 +78,6 @@ instance Eq1 SomeFunctor where
Nothing -> False
Just HRefl -> liftEq eq' lhs rhs
instance Printable SomeFunctor where
printMe cfg (SomeFunctor x) = printMe cfg x
-- | Apply a natural transformation under the 'SomeFunctor'.
--
-- This can change the functor stored in the 'SomeFunctor'. Transformations with
......
......@@ -43,7 +43,7 @@ import Copar.FunctorExpression.Desorting
import Copar.FunctorExpression.Type
import Copar.FunctorDescription
import Copar.Functors.Polynomial
import Copar.Functors.SomeFunctor ( SomeFunctor(SomeFunctor), dynFunctorExprParser )
import Copar.Functors.SomeFunctor ( SomeFunctor(SomeFunctor), someFunctorExprParser )
import Copar.RewriteFunctors
-- | Creates a functor expression parser for the given list of functor parser,
......@@ -119,7 +119,7 @@ parseFunctor name input =
id
(parse (functorExpressionParser identity functorParsers <* eof) name input)
where
functorParsers = map dynFunctorExprParser (reverse (L.sortBy (compare `on` dynPrecedence) registeredFunctors))
functorParsers = map someFunctorExprParser (reverse (L.sortBy (compare `on` dynPrecedence) registeredFunctors))
-- | Options for coalgebra parsing.
......@@ -191,7 +191,7 @@ parseCoalgebra config name input =
name
input
)
where functorParsers = map dynFunctorExprParser (reverse (L.sortBy (compare `on` dynPrecedence) registeredFunctors))
where functorParsers = map someFunctorExprParser (reverse (L.sortBy (compare `on` dynPrecedence) registeredFunctors))
-- | Read coalgebra from file. See 'parseCoalgebra' for details.
......
......@@ -13,7 +13,6 @@ import qualified Data.Vector as V
import Copar.Coalgebra.Parser
import Copar.FunctorExpression.Sorts
import Copar.FunctorExpression.Type
import Copar.FunctorExpression.Printable
import Copar.FunctorDescription
import Copar.RefinementInterface
......@@ -82,9 +81,6 @@ sortTableSpec = describe "sortTable" $ do
, SomeFunctor (Identity ())
]
instance Printable Identity where
printMe cfg (Identity x) = withName cfg "Identity" <> x
type instance Label Identity = ()
type instance Weight Identity = ()
type instance F1 Identity = ()
......@@ -94,7 +90,8 @@ instance FunctorDescription Identity where
syntaxExample = undefined
description = undefined
precedence = undefined
functorExprParser = undefined
functorExprParser = undefined
functorExprPrinter cfg (Identity x) = withName cfg "Identity" <> x
instance RefinementInterface Identity where
init = undefined
update = undefined
......@@ -116,7 +113,8 @@ instance FunctorDescription Twice where
syntaxExample = undefined
description = undefined
precedence = undefined
functorExprParser = undefined
functorExprParser = undefined
functorExprPrinter cfg (Twice a b) = withName cfg "Twice" <> a <> " " <> b
instance RefinementInterface Twice where
init = undefined
update = undefined
......@@ -125,9 +123,6 @@ instance ParseMorphism Twice where
instance Show1 Twice where
liftShowsPrec = undefined
instance Printable Twice where
printMe cfg (Twice a b) = withName cfg "Twice" <> a <> " " <> b
type instance Label Maybe = ()
type instance Weight Maybe = ()
type instance F1 Maybe = ()
......@@ -137,14 +132,13 @@ instance FunctorDescription Maybe where
syntaxExample = undefined
description = undefined
precedence = undefined
functorExprParser = undefined
functorExprParser = undefined
functorExprPrinter _ maybe = case maybe of
Just x -> "Just " <> x
Nothing -> "Nothing"
instance RefinementInterface Maybe where
init = undefined
update = undefined
instance ParseMorphism Maybe where
parseMorphismPoint = undefined
instance Printable Maybe where
printMe _ maybe = case maybe of
Just x -> "Just " <> x
Nothing -> "Nothing"
......@@ -52,4 +52,4 @@ printParseableFunctorSpec = describe "printParseableFunctor" $ do
it_is_eq "P(PX)" "P(PX)"
it "correctly prints a variable as X" $
printParseableFunctor @SomeFunctor Variable `shouldBe` "X"
printParseableFunctor Variable `shouldBe` "X"
Markdown is supported
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