Give up about the annoying breaking change in base about Monoid / Semigroup

This commit is contained in:
Tissevert 2019-05-05 12:27:03 +02:00
parent 1c93600ecf
commit 199df91c71
1 changed files with 6 additions and 4 deletions

View File

@ -10,10 +10,12 @@ import Data.List (intercalate)
data Stream a = Stream [(a, Stream a)] deriving Show
instance Monoid (Stream a) where
mempty = fromList []
mappend (Stream []) b = b
mappend (Stream pairs) b = Stream $ (\(a, stream) -> (a, stream `mappend` b)) <$> pairs
empty :: Stream a
empty = fromList []
append :: Stream a -> Stream a -> Stream a
append (Stream []) b = b
append (Stream pairs) b = Stream $ (\(a, stream) -> (a, stream `append` b)) <$> pairs
fromList :: [a] -> Stream a
fromList [] = Stream []