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

Use more descriptive type for H1 Polynomial

Instead of an unlabeled tuple
parent 5dc7c87f
......@@ -18,6 +18,7 @@ module MA.Functors.Polynomial
, Factor(..)
, ConstSet(..)
, Exponent(..)
, PolyH1(..)
) where
import Control.Monad
......@@ -26,6 +27,7 @@ import Data.List.NonEmpty (NonEmpty(..))
import qualified Data.List.NonEmpty as NonEmpty
import Data.Traversable
import Data.Word (Word8)
import GHC.Generics (Generic)
import qualified Data.Vector.Utils as V
import Data.Text (Text)
......@@ -36,6 +38,7 @@ import Text.Megaparsec
import Data.Eq.Deriving (deriveEq1)
import Text.Show.Deriving (deriveShow1)
import Lens.Micro
import Control.DeepSeq
import MA.Coalgebra.Parser
import MA.Coalgebra.RefinementTypes
......@@ -155,8 +158,20 @@ toSub :: Three
toSub = 2
-- | (Index in Sum, Number of variable Factors, Constant factors)
type instance H1 Polynomial = (Int, Int, Vector Int)
-- | H1 for Polynomial
--
-- TODO: Use unboxed vector for constants
data PolyH1 = PolyH1
{ polyH1Summand :: {-# UNPACK #-} Int
-- ^ Index into sum
, polyH1Variables :: {-# UNPACK #-} Int
-- ^ Number of variable factors
, polyH1Constants :: {-# UNPACK #-} (Vector Int)
-- ^ Values of constant factors
}
deriving (Eq,Show,Ord,NFData,Generic)
type instance H1 Polynomial = PolyH1
-- | Index of this edge into the product
......@@ -198,7 +213,7 @@ parseSum1 sum@(Sum (product :| [])) = do
-- This avoids strange situations where a constant calle 'inj' exists and the
-- input starts with inj.
(try parseSumPrefix >>= parseSum sum) <|>
(first (uncurry (0,,)) <$> parseProduct1 product)
(first (uncurry (PolyH1 0)) <$> parseProduct1 product)
parseSum1 other = parseSumPrefix >>= parseSum other -- otherwise, require 'inj'
<?> "coproduct injection"
......@@ -215,7 +230,7 @@ parseSum (Sum summands) i = do
(h1, successors) <- parseProduct1 (summands NonEmpty.!! i)
return (uncurry (i,,) h1, successors)
return (uncurry (PolyH1 i) h1, successors)
----------- Products parser
......@@ -307,7 +322,7 @@ someName v = do
instance RefinementInterface Polynomial where
init :: H1 Polynomial -> [Label Polynomial] -> Weight Polynomial
init (_,n,_) _ = VU.replicate n True
init h1 _ = VU.replicate (polyH1Variables h1) True
update ::
[Label Polynomial]
......
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