List Info

Thread: "ocaml_beginners"::[] Re: Generate the combinations of K distinct objects chosen from an N-element l




"ocaml_beginners"::[] Re: Generate the combinations of K distinct objects chosen from an N-element l
user name
2006-11-14 16:10:06

--- roparzhhemon < roparzhhemon%40yahoo.com.br">roparzhhemonyahoo.com.br> wrote:

> If I understood the original question correctly, the point was to
> create a "polymorphic&quot;
> function that works as well, say, on ["a&quot;;"b";&quot;c";"d&quot;] as on
> [1;2;3;4]. This is why the
> *list* l (and not just its length n) is an argument in my function.

I did not understand the question that way, but it is a minor
difference.

In case it was not clear, my point was that 1 and l, as 0 and O look
very similar when rendered with certain fonts that are common for
source code editing. So it is a bad idea to use them as variable
names if you aim for readability.

PS:
let cons h t = h::t;;
let rec comb es k = match (es, k) with
| ([], 0) -> [[]]
| ([], _) -> []
| (h::t, _) ->
List.rev_append
(List.map (cons h) (comb t (k-1)))
(comb t k);;

__________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )