aboutsummaryrefslogtreecommitdiff
path: root/backend/backendsupport.dcl
blob: 45ac506edee100608753b0b9804df8044d5bd9d9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
	module owner: Ronny Wichers Schreur
*/
definition module backendsupport

from StdArray import class Array(size,usize)
from StdInt import class +,class ==
from StdFunc import `bind`

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 0
	where
		arraySize
			=	size array
		foldrA index
			| index == arraySize
				=	result
			// otherwise
				=	function array.[index] (foldrA (index+1))