Monad?
This commit is contained in:
parent
dd3c3b1d9e
commit
011050fe3a
@ -19,6 +19,13 @@ instance Applicative GoodList where
|
|||||||
(Singleton f) <*> x = fmap f x
|
(Singleton f) <*> x = fmap f x
|
||||||
(Multiple a b c) <*> x = append (append (fmap a x) (b <*> x)) (fmap c x)
|
(Multiple a b c) <*> x = append (append (fmap a x) (b <*> x)) (fmap c x)
|
||||||
|
|
||||||
|
-- Needs to be proven
|
||||||
|
instance Monad GoodList where
|
||||||
|
return = pure
|
||||||
|
Empty >>= _ = Empty
|
||||||
|
Singleton x >>= f = f x
|
||||||
|
Multiple a b c >>= f = append (append (f a) (b >>= f)) (f c)
|
||||||
|
|
||||||
instance Semigroup (GoodList a) where
|
instance Semigroup (GoodList a) where
|
||||||
(<>) = append
|
(<>) = append
|
||||||
|
|
||||||
@ -34,7 +41,6 @@ instance Show a => Show (GoodList a) where
|
|||||||
show' (Multiple a Empty c) = show a ++ ", " ++ show c
|
show' (Multiple a Empty c) = show a ++ ", " ++ show c
|
||||||
show' (Multiple a b c) = show a ++ ", " ++ show' b ++ ", " ++ show c
|
show' (Multiple a b c) = show a ++ ", " ++ show' b ++ ", " ++ show c
|
||||||
|
|
||||||
|
|
||||||
singleton :: a -> GoodList a
|
singleton :: a -> GoodList a
|
||||||
singleton = Singleton
|
singleton = Singleton
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user