diff options
| author | Edoardo La Greca | 2025-09-11 16:16:06 +0200 |
|---|---|---|
| committer | Edoardo La Greca | 2025-09-11 16:16:06 +0200 |
| commit | 04edf91c24af0cbe29a056c1a05ccffce05c293d (patch) | |
| tree | 1eb6e35d0390449695542bc344ae11fef24049a0 /lec07/JoinList.hs | |
| parent | f5d3c9762c02284a0ae07541d963aa733cad8a25 (diff) | |
fix syntax of most functions in lecture 7's exercises
Diffstat (limited to 'lec07/JoinList.hs')
| -rw-r--r-- | lec07/JoinList.hs | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/lec07/JoinList.hs b/lec07/JoinList.hs index 61df8da..4eba3d2 100644 --- a/lec07/JoinList.hs +++ b/lec07/JoinList.hs @@ -1,5 +1,7 @@ module JoinList where +import Sized + data JoinList m a = Empty | Single m a | Append m (JoinList m a) (JoinList m a) @@ -9,11 +11,11 @@ data JoinList m a = Empty tag :: Monoid m => JoinList m a -> m tag Empty = mempty -tag Single m _ = m -tag Append m _ _ = m +tag (Single m _) = m +tag (Append m _ _) = m (+++) :: Monoid m => JoinList m a -> JoinList m a -> JoinList m a -(+++) jl1 jl2 = mappend jl1 jl2 +(+++) jl1 jl2 = Append (mappend (tag jl1) (tag jl2)) jl1 jl2 -- Exercise 2 @@ -23,10 +25,10 @@ indexJ n (Single _ a) | n == 0 = Just a | otherwise = Nothing indexJ n (Append m jl1 jl2) - | n < 0 || n >= m = Nothing - | n < tag1 = indexJ n jl1 - | n >= tag1 = indexJ (n - tag1) jl2 - where tag1 = tag jl1 + | n < 0 || n >= (getSize $ size m) = Nothing + | n < s1 = indexJ n jl1 + | n >= s1 = indexJ (n - s1) jl2 + where s1 = getSize $ size $ tag jl1 dropJ :: (Sized b, Monoid b) => Int -> JoinList b a -> JoinList b a dropJ _ Empty = Empty @@ -35,7 +37,6 @@ dropJ n jl dropJ n (Single _ _) | n >= 1 = Empty dropJ n (Append m jl1 jl2) - | n >= m = Empty - | n >= tag1 = jl2 - where tag1 = tag jl1 - + | n >= (getSize $ size m) = Empty + | n >= s1 = jl2 + where s1 = getSize $ size $ tag jl1 |