Monoid-instance for Load
This commit is contained in:
parent
03f9bc4f89
commit
ead6aacfc2
@ -85,6 +85,19 @@ data Load -- = ByTutorial { countsToLoad :: Bool } | ByProportion { load :: Rati
|
|||||||
deriving (Show, Read, Eq)
|
deriving (Show, Read, Eq)
|
||||||
derivePersistField "Load"
|
derivePersistField "Load"
|
||||||
|
|
||||||
|
instance Semigroup Load where
|
||||||
|
(Load byTut prop) <> (Load byTut' prop') = Load byTut'' (prop + prop')
|
||||||
|
where
|
||||||
|
byTut''
|
||||||
|
| Nothing <- byTut = byTut'
|
||||||
|
| Nothing <- byTut' = byTut
|
||||||
|
| Just a <- byTut
|
||||||
|
, Just b <- byTut' = Just $ a || b
|
||||||
|
|
||||||
|
instance Monoid Load where
|
||||||
|
mempty = Load Nothing 0
|
||||||
|
mappend = (<>)
|
||||||
|
|
||||||
{- Use (is _ByTutorial) instead of this unneeded definition:
|
{- Use (is _ByTutorial) instead of this unneeded definition:
|
||||||
isByTutorial :: Load -> Bool
|
isByTutorial :: Load -> Bool
|
||||||
isByTutorial (ByTutorial {}) = True
|
isByTutorial (ByTutorial {}) = True
|
||||||
|
|||||||
Reference in New Issue
Block a user