diff options
Diffstat (limited to 'backend/backendsupport.icl')
-rw-r--r-- | backend/backendsupport.icl | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/backend/backendsupport.icl b/backend/backendsupport.icl new file mode 100644 index 0000000..ea92a7b --- /dev/null +++ b/backend/backendsupport.icl @@ -0,0 +1,66 @@ +implementation module backendsupport + +from StdArray import size, size_u +from StdFunc import `bind` +from StdInt import +, == + +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)) |