summaryrefslogtreecommitdiff
path: root/lec07/JoinList.hs
diff options
context:
space:
mode:
authorEdoardo La Greca2025-09-10 21:29:24 +0200
committerEdoardo La Greca2025-09-10 21:29:24 +0200
commitf5d3c9762c02284a0ae07541d963aa733cad8a25 (patch)
tree7b23cd85c78958ac0d38395064b9b77fc76d0d97 /lec07/JoinList.hs
parent125dcc2372f01da088b603676bf4870e6aafb843 (diff)
implement dropJ from second exercise of lecture 7
Diffstat (limited to 'lec07/JoinList.hs')
-rw-r--r--lec07/JoinList.hs11
1 files changed, 11 insertions, 0 deletions
diff --git a/lec07/JoinList.hs b/lec07/JoinList.hs
index 7ec30a9..61df8da 100644
--- a/lec07/JoinList.hs
+++ b/lec07/JoinList.hs
@@ -28,3 +28,14 @@ indexJ n (Append m jl1 jl2)
| n >= tag1 = indexJ (n - tag1) jl2
where tag1 = tag jl1
+dropJ :: (Sized b, Monoid b) => Int -> JoinList b a -> JoinList b a
+dropJ _ Empty = Empty
+dropJ n jl
+ | n <= 0 = jl
+dropJ n (Single _ _)
+ | n >= 1 = Empty
+dropJ n (Append m jl1 jl2)
+ | n >= m = Empty
+ | n >= tag1 = jl2
+ where tag1 = tag jl1
+