From ca0fea108f9c946ae785efbff4b9b36123674136 Mon Sep 17 00:00:00 2001 From: pingu Date: Fri, 1 Mar 2024 11:19:08 +0100 Subject: [PATCH] simpler append function --- src/GoodList.hs | 4 +--- test/Main.hs | 6 +++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/GoodList.hs b/src/GoodList.hs index 47f66c6..37b50d9 100644 --- a/src/GoodList.hs +++ b/src/GoodList.hs @@ -55,9 +55,7 @@ snoc (Multiple a b c) = Multiple a (b `snoc` c) append :: GoodList a -> GoodList a -> GoodList a append Empty ys = ys 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 +append (Multiple a b c) ys = cons a . append b $ cons c ys join :: GoodList (GoodList a) -> GoodList a join Empty = Empty diff --git a/test/Main.hs b/test/Main.hs index ed63923..7943648 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -3,6 +3,10 @@ import GoodList abc :: GoodList Char abc = cons 'a' $ cons 'b' $ cons 'c' Empty +def :: GoodList Char +def = cons 'd' $ cons 'e' $ cons 'f' Empty main :: IO () -main = print abc +main = print abc >> + print def >> + print (abc `append` def)