diff options
author | Camil Staps | 2016-02-02 19:24:50 +0100 |
---|---|---|
committer | Camil Staps | 2016-02-02 19:24:50 +0100 |
commit | a7d7542dc646a5fd124ef71e71ce260889f1701b (patch) | |
tree | 04ed89503bbb3cc9933273a1326a53ca724c3492 /1415/fp1/week3/mart/StdSortList.icl | |
parent | week6 camil: working positioning of lines by putting empties at left and righ... (diff) |
Diffstat (limited to '1415/fp1/week3/mart/StdSortList.icl')
-rw-r--r-- | 1415/fp1/week3/mart/StdSortList.icl | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/1415/fp1/week3/mart/StdSortList.icl b/1415/fp1/week3/mart/StdSortList.icl new file mode 100644 index 0000000..db71a36 --- /dev/null +++ b/1415/fp1/week3/mart/StdSortList.icl @@ -0,0 +1,50 @@ +implementation module StdSortList
+
+import StdEnv
+
+:: SortList a :== ([a], a)
+
+newSortList :: SortList a
+newSortList = ([], abort "Empty list")
+
+memberSort :: a (SortList a) -> Bool | Eq, Ord a
+memberSort e ([], y) = y
+memberSort e ([x:xs], y)
+| e == x = True
+| e > x = False
+| otherwise = memberSort e (xs, y)
+
+insertSort :: a (SortList a) -> SortList a | Ord a
+insertSort e ([], y) = ([e], e)
+insertSort e ([x:xs], y)
+| e <= x = ([e:x:xs], y)
+| otherwise = ([x:fst result], snd result)
+ where result = insertSort e (xs, y)
+
+removeFirst :: a (SortList a) -> SortList a | Eq, Ord a
+removeFirst e ([], y) = y
+removeFirst e ([e], e) = newSortList
+removeFirst e ([x:xs], y)
+| e == x = ([xs], y)
+removeFirst _ _ = abort ""
+
+removeAll :: a (SortList a) -> SortList a | Eq, Ord a
+removeAll _ _ = abort ""
+
+elements :: (SortList a) -> [a]
+elements _ = abort ""
+
+count :: (SortList a) -> Int
+count _ = abort ""
+
+minimum :: (SortList a) -> a
+minimum _ = abort ""
+
+maximum :: (SortList a) -> a
+maximum _ = abort ""
+
+mergeSortList :: (SortList a) (SortList b) -> (SortList a)
+mergeSortList _ _ = abort ""
+
+Start :: String
+Start = newSortList
|