Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type Tree =
- | Empty
- | Node of Tree * int * Tree
- // printTree : Tree -> int
- let rec printTree t =
- match t with
- | Empty -> printf "nul"; 0
- | Node (l, v, r) -> printf "%A (" v
- let lc = printTree l
- printf ", "
- let rc = printTree r
- printf ")"
- lc + rc + 1
- printTree (Node (Empty, 1, Empty)) |> ignore
- // printTree'cps : Tree -> (int -> 'a) -> 'a
- let rec printTree'cps t k =
- match t with
- | Empty -> k (printf "nul"; 0)
- | Node (l, v, r) -> printf "%A (" v
- printTree'cps l
- (fun lc ->
- printf ", "
- printTree'cps r
- (fun rc ->
- printf ")"
- k (lc + rc + 1)
- )
- )
- printTree'cps (Node (Node (Empty, 2, Empty), 1, (Node (Empty, 3, Empty)))) (fun cnt -> printfn "\ncount = %A" cnt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement