T.P.Readers.LaTeX.Parsing: Monoid and Semigroup instances for TokStream.
This commit is contained in:
parent
6abcde0bf7
commit
f9a4e049c5
1 changed files with 8 additions and 0 deletions
|
@ -251,6 +251,14 @@ instance Default LaTeXState where
|
|||
data TokStream = TokStream !Bool [Tok]
|
||||
deriving (Show)
|
||||
|
||||
instance Semigroup TokStream where
|
||||
(TokStream exp1 ts1) <> (TokStream exp2 ts2) =
|
||||
TokStream (if null ts1 then exp2 else exp1) (ts1 <> ts2)
|
||||
|
||||
instance Monoid TokStream where
|
||||
mempty = TokStream False mempty
|
||||
mappend = (<>)
|
||||
|
||||
instance Monad m => Stream TokStream m Tok where
|
||||
uncons (TokStream _ []) = return Nothing
|
||||
uncons (TokStream _ (t:ts)) = return $ Just (t, TokStream False ts)
|
||||
|
|
Loading…
Reference in a new issue