Commit ed7717ce authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2003-11-26 20:08:23 by beppe] programmed count in tail recursive way

Original author: beppe
Date: 2003-11-26 20:08:23+00:00
parent 9a27d4c7
(*********function *********)
let fun count([Any*]->Int)
let fun count_bad([Any*]->Int)
[] -> 0
| [_;t] -> 1+count(t);;
(* tail recursive definition *)
let fun count(x : [Any*]) : Int =
let tr_count((Int,[Any*]) -> Int)
| (n,[]) -> n
| (n,[_;t]) -> tr_count(n+1,t)
in tr_count(0,x)
(***************************)
(*****************************************************************
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment