blob: 31379ec3067d9da79dc0b9e54c4da955e6bc3922 (
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
|
module revtwice
/*
Reversing a list a number of times using Twice.
Increase stack size to 1m and heap size to 4m to run this program.
A list containing 25 integers is reversed 65536 times by means
of four applications of the higher order function Twice.
*/
(<) infix 4 :: !Int !Int -> Bool
(<) a b = code inline {
ltI
}
(+) infixl 6 :: !Int !Int -> Int
(+) a b = code inline {
addI
}
(-) infixl 6 :: !Int !Int -> Int
(-) a b = code inline {
subI
}
fromto :: !Int !Int -> [Int]
fromto a b
| b < a = []
| otherwise = [a:fromto (a+1) b]
//import StdInt, StdEnum
Revv:: [Int] -> [Int]
Revv l = Rev l []
where
Rev::[Int] [Int] -> [Int]
Rev [x:r] list = Rev r [x : list]
Rev [] list = list
Twice::(x -> x) x -> x
Twice f x = f (f x)
Start::[Int]
Start = Twice Twice Twice Twice Revv (fromto 1 25)
|