diff options
author | ronny | 2000-02-22 15:53:02 +0000 |
---|---|---|
committer | ronny | 2000-02-22 15:53:02 +0000 |
commit | 4c554becf5c7fd9d5717a097f278c55f28cb25a0 (patch) | |
tree | 895fb41b61953b5bd9a4b26ff073258782741426 /backend/backendsupport.dcl | |
parent | Initial import (diff) |
Initial import
git-svn-id: https://svn.cs.ru.nl/repos/clean-compiler/trunk@97 1f8540f1-abd5-4d5b-9d24-4c5ce8603e2d
Diffstat (limited to 'backend/backendsupport.dcl')
-rw-r--r-- | backend/backendsupport.dcl | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/backend/backendsupport.dcl b/backend/backendsupport.dcl new file mode 100644 index 0000000..8ca0091 --- /dev/null +++ b/backend/backendsupport.dcl @@ -0,0 +1,69 @@ +definition module backendsupport + +from StdArray import size, size_u +from StdFunc import `bind` +from StdInt import +, == + +import utilities + +identity + :== \x -> x + +// binding sugar +(==>) infix +(==>) f g + :== f `bind` g + +// o` :== flip o +(o`) infixr +(o`) f g + :== \x -> g (f x) + +(:-) infixl +(:-) a f + :== f a + + +foldState function list + :== foldState list + where + foldState [] + = identity + foldState [hd:tl] + = function hd + o` foldState tl + +foldStateA function array + :== foldStateA 0 + where + arraySize + = size array + foldStateA index + | index == arraySize + = identity + // otherwise + = function array.[index] + o` foldStateA (index+1) + +foldStateWithIndexA function array + :== foldStateWithIndexA 0 + where + arraySize + = size array + foldStateWithIndexA index + | index == arraySize + = identity + // otherwise + = function index array.[index] + o` foldStateWithIndexA (index+1) + +foldrA function result array + :== foldrA result 0 + where + arraySize + = size array + foldrA result index + | index == arraySize + = result + // otherwise + = function array.[index] (foldrA result (index+1)) |