Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist-newstyle
16 changes: 9 additions & 7 deletions src/Observations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,16 @@ unTEs (TEs x) = x
instance Functor TimedEvents where
fmap f (TEs tes) = TEs [ (t,f e) | (t,e) <- tes ]

instance Monoid a => Monoid (TimedEvents a) where
mempty = TEs []
mappend as bs =
fmap mappendMergeResult (mergeEvents as bs)
instance Semigroup a => Semigroup (TimedEvents a) where
as <> bs =
fmap mappendMergeResult (mergeEvents as bs)
where
mappendMergeResult (OnlyInLeft a) = a
mappendMergeResult (InBoth a b) = a `mappend` b
mappendMergeResult (OnlyInRight b) = b
mappendMergeResult (OnlyInLeft a) = a
mappendMergeResult (InBoth a b) = a <> b
mappendMergeResult (OnlyInRight b) = b

instance Semigroup a => Monoid (TimedEvents a) where
mempty = TEs []

-- mconcat = --TODO: optimise mconcat to do more balanced merges

Expand Down
4 changes: 2 additions & 2 deletions src/XmlUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import Text.XML.HaXml.Types (QName(..))
import Text.XML.HaXml.XmlContent
import Data.Time

attrStr :: Monad m => QName -> Element t -> m String
attrStr :: MonadFail m => QName -> Element t -> m String
attrStr n (Elem _ as _) =
case lookup n as of
Nothing -> fail ("expected attribute " ++ localName n)
Just av -> return (attr2str av)

attrRead :: (Read b, Monad m) => QName -> Element t -> m b
attrRead :: (Read b, MonadFail m) => QName -> Element t -> m b
attrRead n e = do
str <- attrStr n e
case reads str of
Expand Down