{-# LANGUAGE CPP #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Data.Massiv.Core.Computation
( Comp(..)
, pattern Par
) where
import Control.DeepSeq (NFData (..), deepseq)
#if !MIN_VERSION_base(4,11,0)
import Data.Semigroup
#endif
data Comp
= Seq
| ParOn [Int]
deriving (Show, Eq)
pattern Par :: Comp
pattern Par <- ParOn [] where
Par = ParOn []
instance NFData Comp where
rnf comp =
case comp of
Seq -> ()
Par -> ()
ParOn wIds -> wIds `deepseq` ()
{-# INLINE rnf #-}
instance Monoid Comp where
mempty = Seq
{-# INLINE mempty #-}
mappend = joinComp
{-# INLINE mappend #-}
instance Semigroup Comp where
(<>) = joinComp
{-# INLINE (<>) #-}
joinComp :: Comp -> Comp -> Comp
joinComp Par _ = Par
joinComp _ Par = Par
joinComp (ParOn w1) (ParOn w2) = ParOn $ w1 ++ w2
joinComp c@(ParOn _) _ = c
joinComp _ c@(ParOn _) = c
joinComp _ _ = Seq
{-# INLINE joinComp #-}