-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathTask5_1.hs
39 lines (30 loc) · 1004 Bytes
/
Task5_1.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module Task5_1 where
import Todo(todo)
data DList a = DNil
| DCons {
left :: (DList a),
current :: a,
right :: (DList a)
}
instance (Show a) => Show (DList a) where
show it = "[" ++ showBody it ++ "]"
where showBody DNil = ""
showBody (DCons _ h DNil) = show h
showBody (DCons _ h t) = show h ++ ", " ++ showBody t
instance (Eq a) => Eq (DList a) where
DNil == DNil = True
(DCons _ h1 t1) == (DCons _ h2 t2) = h1 == h2 && t1 == t2
_ == _ = False
list2dlist :: [a] -> DList a
list2dlist lst = list2dlist' DNil lst
list2dlist' :: DList a -> [a] -> DList a
list2dlist' _ [] = DNil
list2dlist' left (h: t) =
let rec = DCons left h (list2dlist' rec t)
in rec
index :: DList a -> Int -> a
index = todo
insertAt :: DList a -> Int -> a -> DList a
insertAt list index value = todo
removeAt :: DList a -> Int -> DList a
removeAt list index = todo