datatype StringList CONS of string unit StringList NIL fun filter NIL

 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
datatype StringList
= CONS of string * (unit -> StringList)
| NIL
fun filter p NIL = NIL
| filter p (CONS (x,xf)) =
if p x then CONS (x, fn() => filter p (xf()))
else filter p (xf())
fun concat (xq, 0) = ""
| concat (NIL, n) = ""
| concat (CONS (x,xf), n) = x ^ " " ^ concat (xf(),n-1)
fun binString 0 = ""
| binString x = binString(x div 2)^(Int.toString (x mod 2))
val bin =
let
fun genBin 0 = NIL
| genBin x = CONS(binString x, fn() => genBin(x+1))
in
CONS("1", fn() => genBin(2))
end
fun main () =
let
val filteredBin = bin
in
print(concat(bin, 10))
end