Version française
Home     About     Download     Resources     Contact us    
Browse thread
Combinatorics in a functional way
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Gabriel Kerneis <gabriel.kerneis@e...>
Subject: Re: [Caml-list] Combinatorics in a functional way
Le Wed, 21 Feb 2007 12:29:06 +0100, "Nicolas Pouillard"
<nicolas.pouillard@gmail.com> a écrit :
> So in your case just use a function like range:
> 
> let range n =
>  let rec aux i l =
>      if i = 0 then l else i::(aux (i-1) l)
>  in List.rev ( aux n [] )
> ;;

I'd rather use the tail recursive version :

let range n =
  let rec aux i l =
      if i = 0 then l else aux (i-1) (i::l)
  in aux n []
 ;;


-- 
Gabriel Kerneis