3 fun digit n
= chr(ord #
"0" + n
)
5 if n
>=0 andalso n
<=9 then digit n
:: acc
6 else digits (n
div 10, digit(n
mod 10) :: acc
)
8 fun int_to_string(n
) = implode(digits(n
,[]))
10 fun rev l
= (* linear
-time reversal
of lists
! *)
11 let fun loop([], acc
) = acc
12 |
loop(x
::xs
, acc
) = loop(xs
, x
::acc
)
18 | foldR f
b (x
::xs
) = f
x (foldR f b xs
)
20 fun curry f x y
= f(x
,y
)
22 datatype 'a Option
= None | Some
of 'a
27 | Br
of 'a
* 'a tree
* 'a tree
29 fun max(i
:int, j
) = if i
>j
then i
else j
30 fun search p Lf
= false
31 | search
p (Br(x
,t1
,t2
)) =
33 else search (fn y
=> y
=x
orelse p y
) t1
orelse
34 search (fn y
=> y
=x
orelse p y
) t2
37 | mk_tree n
= let val t
= mk_tree(n
-1)
40 val it
= if search (fn _
=> false) (mk_tree
20) then print
"true\n"