Commit e1ae6bbf authored by Bastian Kauschke's avatar Bastian Kauschke
Browse files

add type alias for monoid valued

parent e5e572ff
......@@ -8,6 +8,7 @@ module Copar.FunctorDescription
, formatFunctorDescription
, formatFunctorDescriptions
, dynPrecedence
, dynFunctorDescription
, dynFunctorExprParser
)
where
......@@ -31,8 +32,8 @@ class (Suitable f) => FunctorDescription f where
precedence :: Int
functorExprParser :: FunctorParser f
dynFunctorDescription :: DynFunctorDescription
dynFunctorDescription = DynFunctorDescription (Proxy :: Proxy f)
dynFunctorDescription :: forall f. FunctorDescription f => DynFunctorDescription
dynFunctorDescription = DynFunctorDescription (Proxy :: Proxy f)
data DynFunctorDescription where
DynFunctorDescription :: FunctorDescription f => Proxy f -> DynFunctorDescription
......
......@@ -5,10 +5,7 @@ module Copar.Functors (registeredFunctors) where
import Prelude hiding ( product )
import Data.Ratio
import Data.Word
import Data.Float.Utils
import Data.Bits.Monoid
import Data.Semigroup ( Max(..), Min(..) )
import Copar.FunctorDescription
import Copar.Functors.Bag ( Bag )
......@@ -16,16 +13,22 @@ import Copar.Functors.Distribution ( Distribution )
import Copar.Functors.GroupValued ( GroupValued, OrderedComplex )
import Copar.Functors.Polynomial ( Polynomial )
import Copar.Functors.Powerset ( Powerset )
import Copar.Functors.MonoidValued ( SlowMonoidValued )
import Copar.Functors.MonoidValued ( MaxIntValued
, MinIntValued
, MaxDoubleValued
, MinDoubleValued
, BitAndValued
, BitOrValued
)
registeredFunctors :: [DynFunctorDescription]
registeredFunctors =
[ dynFunctorDescription @(SlowMonoidValued (Max Int))
, dynFunctorDescription @(SlowMonoidValued (Min Int))
, dynFunctorDescription @(SlowMonoidValued (MaxDouble))
, dynFunctorDescription @(SlowMonoidValued (MinDouble))
, dynFunctorDescription @(SlowMonoidValued (BitAnd Word64))
, dynFunctorDescription @(SlowMonoidValued (BitOr Word64))
[ dynFunctorDescription @MaxIntValued
, dynFunctorDescription @MinIntValued
, dynFunctorDescription @MaxDoubleValued
, dynFunctorDescription @MinDoubleValued
, dynFunctorDescription @BitAndValued
, dynFunctorDescription @BitOrValued
, dynFunctorDescription @(GroupValued Int)
, dynFunctorDescription @(GroupValued EqDouble)
......
......@@ -9,7 +9,15 @@
-- The 'RefinementInterface' implementation for such functors doesn't fulfil the
-- same runtime complexity criteria as the other functors and it also uses tons
-- of space, but it works and satisfies the axioms.
module Copar.Functors.MonoidValued (SlowMonoidValued(..))
module Copar.Functors.MonoidValued
( SlowMonoidValued(..)
, MaxIntValued
, MinIntValued
, MaxDoubleValued
, MinDoubleValued
, BitAndValued
, BitOrValued
)
where
import Data.List ( foldl', intersperse )
......@@ -46,8 +54,7 @@ import Data.Proxy
newtype SlowMonoidValued m a = SlowMonoidValued a
-- TODO We may want to change MonoidValuedDiscription to a type class,
-- this would allow us to simplify these instances.
-- TODO Remove Printable in favor of FunctorDescription
instance Printable (SlowMonoidValued (Max Int)) where
precedence _ = 250
......@@ -138,6 +145,7 @@ makeMVHelp (Proxy :: Proxy m) =
where syntax x = functorSyntax x (mvOperation @m)
-- | The @(ℤ, max)^X@ functor
type MaxIntValued = SlowMonoidValued (Max Int)
instance MonoidValuedDescription (Max Int) where
mvName = "Max"
mvSet = ["Z", "ℤ"]
......@@ -147,6 +155,7 @@ instance MonoidValuedDescription (Max Int) where
mvTerm = "int"
-- | The @(ℤ, min)^X@ functor
type MinIntValued = SlowMonoidValued (Min Int)
instance MonoidValuedDescription (Min Int) where
mvName = "Min"
mvSet = ["Z", "ℤ"]
......@@ -155,8 +164,8 @@ instance MonoidValuedDescription (Min Int) where
mvPrecedence = 40
mvTerm = "int"
-- | The @(ℝ, max)^X@ functor
type MaxDoubleValued = SlowMonoidValued (MaxDouble)
instance MonoidValuedDescription MaxDouble where
mvName = "Max"
mvSet = ["R", "ℝ"]
......@@ -165,8 +174,8 @@ instance MonoidValuedDescription MaxDouble where
mvPrecedence = 30
mvTerm = "real"
-- | The @(ℝ, min)^X@ functor
type MinDoubleValued = SlowMonoidValued (MinDouble)
instance MonoidValuedDescription MinDouble where
mvName = "Min"
mvSet = ["R", "ℝ"]
......@@ -175,8 +184,8 @@ instance MonoidValuedDescription MinDouble where
mvPrecedence = 20
mvTerm = "real"
-- | The @(Word, and)^X@ functor
type BitAndValued = SlowMonoidValued (BitAnd Word64)
instance MonoidValuedDescription (BitAnd Word64) where
mvName = "BitAnd"
mvSet = ["Word"]
......@@ -186,12 +195,13 @@ instance MonoidValuedDescription (BitAnd Word64) where
mvTerm = "0xCAFE"
-- | The @(Word, or)^X@ functor
type BitOrValued = SlowMonoidValued (BitOr Word64)
instance MonoidValuedDescription (BitOr Word64) where
mvName = "BitOr"
mvSet = ["Word"]
mvOperation = "or"
mvDescription = "bitvectors and bitwise 'or' as monoid weight"
mvPrecedence = 00
mvPrecedence = 0
mvTerm = "0xCAFE"
......
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