You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
515 B
26 lines
515 B
type ral<'a> =
|
|
| Nil
|
|
| Zero of ral<'a * 'a>
|
|
| One of 'a * ral<'a * 'a>
|
|
|
|
let rec length<'a> (l : ral<'a>) : int =
|
|
match l with
|
|
| Nil -> 0
|
|
| Zero s -> 2 * length s
|
|
| One (_v, s) -> 1 + 2 * length s
|
|
|
|
let rec cons<'a> (x : 'a) (l : ral<'a>) : ral<'a> =
|
|
match l with
|
|
| Nil -> One (x, Nil)
|
|
| Zero s -> One (x, s)
|
|
| One (y, s) -> Zero (cons (x, y) s)
|
|
|
|
let rec loop l =
|
|
let len = length l
|
|
if len < 3000000 then
|
|
let l = cons 42 l
|
|
printfn "len = %d" (length l)
|
|
loop l
|
|
|
|
loop Nil
|
|
loop Nil
|
|
|