diff options
Diffstat (limited to 'lec07/JoinList.hs')
| -rw-r--r-- | lec07/JoinList.hs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lec07/JoinList.hs b/lec07/JoinList.hs index 5c1165e..ccfa838 100644 --- a/lec07/JoinList.hs +++ b/lec07/JoinList.hs @@ -43,3 +43,15 @@ dropJ n jl@(Append m jl1 jl2) where s1 = getSize $ size $ tag jl1 m' = getSize $ size m + +takeJ :: (Sized b, Monoid b) => Int -> JoinList b a -> JoinList b a +takeJ _ Empty = Empty +takeJ n _ | n <= 0 = Empty +takeJ n jl@(Single _ _) = jl +takeJ n jl@(Append m jl1 jl2) + | n >= m' = jl + | n < s1 = takeJ n jl1 + | n >= s1 = jl1 +++ takeJ (n - s1) jl2 + where + s1 = getSize $ size $ tag jl1 + m' = getSize $ size m |