aboutsummaryrefslogtreecommitdiff
path: root/frontend/utilities.dcl
diff options
context:
space:
mode:
authorronny1999-10-05 13:09:14 +0000
committerronny1999-10-05 13:09:14 +0000
commitdb9e59813541e06caece64592854862bab9c0138 (patch)
treeae7cef5982a377261188aed09dc0f0cc95c50f8c /frontend/utilities.dcl
parentStandard project directories initialized by cvs2svn. (diff)
Initial import
git-svn-id: https://svn.cs.ru.nl/repos/clean-compiler/trunk@2 1f8540f1-abd5-4d5b-9d24-4c5ce8603e2d
Diffstat (limited to 'frontend/utilities.dcl')
-rw-r--r--frontend/utilities.dcl92
1 files changed, 92 insertions, 0 deletions
diff --git a/frontend/utilities.dcl b/frontend/utilities.dcl
new file mode 100644
index 0000000..434e7c7
--- /dev/null
+++ b/frontend/utilities.dcl
@@ -0,0 +1,92 @@
+definition module utilities
+
+from StdString import String
+from StdEnv import Eq, not, Ord, IncDec
+import StdMisc, general
+/*
+ For Strings
+*/
+
+stringToCharList :: !String -> [Char]
+charListToString :: ![Char] -> String
+revCharListToString :: !Int ![Char] -> String
+
+isUpperCaseName :: ! String -> Bool
+isLowerCaseName :: ! String -> Bool
+isFunnyIdName :: ! String -> Bool
+isSpecialChar :: ! Char -> Bool
+
+/*
+ For Lists
+*/
+
+mapSt :: !(.a -> (.st -> (.c,.st))) ![.a] !.st -> (![.c],!.st)
+
+app2St :: !(!.(.a -> .(.st -> (.c,.st))),!.(.e -> .(.st -> (.f,.st)))) !(.a,.e) !.st -> (!(.c,.f),!.st)
+
+mapAppendSt :: !(.a -> .(.b -> (.c,.b))) ![.a] !u:[.c] !.b -> !(!u:[.c],!.b)
+
+strictMap :: !(.a -> .b) ![.a] -> [.b]
+
+strictMapAppend :: !(.a -> .b) ![.a] !u:[.b] -> v:[.b], [u <= v]
+
+mapAppend :: !(.a -> .b) ![.a] !u:[.b] -> u:[.b]
+
+//zip2Append :: [.a] [.b] u:[w:(.a,.b)] -> v:[x:(.a,.b)], [w <= x, u <= v]
+
+eqMerge :: ![a] ![a] -> [a] | Eq a
+
+// foldl2 :: !(.c -> .(.a -> .(.b -> .c))) !.c ![.a] ![.b] -> .c
+foldl2 op r l1 l2
+ :== foldl2 r l1 l2
+where
+ foldl2 r [x : xs] [y : ys]
+ = foldl2 (op r x y) xs ys
+ foldl2 r [] []
+ = r
+//foldr2 :: !(.a -> .(.b -> .(.c -> .c))) !.c ![.a] ![.b] -> .c
+
+foldr2 op r l1 l2
+ :== foldr2 r l1 l2
+where
+ foldr2 r [x : xs] [y : ys]
+ = op x y (foldr2 r xs ys)
+ foldr2 r [] []
+ = r
+
+fold2St op l1 l2 st
+ :== fold_st2 l1 l2 st
+where
+ fold_st2 [x : xs] [y : ys] st
+ = op x y (fold_st2 xs ys st)
+ fold_st2 [] [] st
+ = st
+ fold_st2 [] ys st
+ = abort ("fold_st2: second argument list contains more elements" ---> ys)
+ fold_st2 xs [] st
+ = abort ("fold_st2: first argument list contains more elements" ---> xs)
+
+// foldSt :: !(.a -> .(.st -> .st)) ![.a] !.st -> .st
+foldSt op l st :== fold_st l st
+ where
+ fold_st [] st = st
+ fold_st [a:x] st = fold_st x (op a st)
+
+iFoldSt op fr to st :== i_fold_st fr to st
+ where
+ i_fold_st fr to st
+ | fr >= to
+ = st
+ = i_fold_st (inc fr) to (op fr st)
+
+iterateSt op st :== iterate_st op st
+ where
+ iterate_st op st
+ # (continue, st) = op (False, st)
+ | continue
+ = iterate_st op st
+ = st
+
+revAppend :: ![a] ![a] -> [a] // Reverse the list using the second argument as accumulator.
+revMap :: !(.a -> .b) ![.a] !u:[.b] -> u:[.b]
+