diff options
author | Mart Lubbers | 2015-04-16 21:22:20 +0200 |
---|---|---|
committer | Mart Lubbers | 2015-04-16 21:22:20 +0200 |
commit | 6f604b19d3f5966e5c1d7c4fdf3703bd6ff0861c (patch) | |
tree | 96d580507249f7f58368476d9113007d4afcd748 /fp1/week3/mart/StdSortList.icl | |
parent | Added student numbers (diff) |
update to fp2 yay, public and licence
Diffstat (limited to 'fp1/week3/mart/StdSortList.icl')
-rw-r--r-- | fp1/week3/mart/StdSortList.icl | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/fp1/week3/mart/StdSortList.icl b/fp1/week3/mart/StdSortList.icl new file mode 100644 index 0000000..db71a36 --- /dev/null +++ b/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
|