simpler append function

This commit is contained in:
pingu 2024-03-01 11:19:08 +01:00
parent 604206776f
commit ca0fea108f
2 changed files with 6 additions and 4 deletions

View File

@ -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

View File

@ -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)