Re: Stdlib regularity

From: Pierre Weis (
Date: Sun Oct 10 1999 - 22:09:08 MET DST

From: Pierre Weis <>
Message-Id: <>
Subject: Re: Stdlib regularity
Date: Sun, 10 Oct 1999 22:09:08 +0200 (MET DST)
In-Reply-To: <> from "=?iso-8859-1?Q?Mat=EDas?= Giovannini" at Oct 8, 99 11:06:10 am

> Yes! Yes! I always begin my Caml code by writing iota, and I wish it
> were included in the standard library. It's silly simple, and imprescindible.
> let iota n =
> let rec aux l n =
> if n > 0 then aux (n::l) (n-1) else l
> in aux [] n

We may reuse this ``prelude'' code that slightly generalizes iota (named
range in this version of the standard library):

\subsection{Lists of consecutive integers}
\index{Lists of consecutive integers}
\item \verb"interval n m" returns the list of all integers in
increasing order, from \verb"n" to \verb"m".
\item \verb"range n" gives the first n integers.

let interval n m =
 let rec loop l m =
  if n > m then l else loop (m :: l) (pred m) in
 loop [] m;;

let range = interval 1;;

Pierre Weis

INRIA, Projet Cristal,,

This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:26 MET