From 604206776fa469a3ccc55311126ca8864380c2fe Mon Sep 17 00:00:00 2001 From: pingu Date: Thu, 29 Feb 2024 19:02:20 +0100 Subject: [PATCH] Monad, probs --- src/GoodList.hs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/GoodList.hs b/src/GoodList.hs index c24ac19..47f66c6 100644 --- a/src/GoodList.hs +++ b/src/GoodList.hs @@ -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