Monad, probs
This commit is contained in:
parent
011050fe3a
commit
604206776f
@ -22,9 +22,7 @@ instance Applicative GoodList where
|
||||
-- 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)
|
||||
x >>= f = join $ fmap f x
|
||||
|
||||
instance Semigroup (GoodList a) where
|
||||
(<>) = append
|
||||
@ -60,3 +58,8 @@ append (Singleton x) ys = cons x ys
|
||||
append xs Empty = xs
|
||||
append (Multiple a b c) (Singleton y) = Multiple a (snoc b c) y
|
||||
append (Multiple a b c) (Multiple d e f) = Multiple a (snoc b c `append` cons d e) f
|
||||
|
||||
join :: GoodList (GoodList a) -> GoodList a
|
||||
join Empty = Empty
|
||||
join (Singleton x) = x
|
||||
join (Multiple a b c) = append (a `append` join b) c
|
||||
|
Loading…
Reference in New Issue
Block a user