[Haskell-cafe] The range operator

Roel van Dijk vandijk.roel at gmail.com
Mon Apr 7 09:22:13 EDT 2008


class Enum a where
  ...
  -- | Used in Haskell's translation of [n,n'..m].
  enumFromThenTo :: a -> a -> a -> [a]

So [x, y .. z] becomes "enumFromThenTo x y z".

Each instance of Enum is free to implement enumFromThenTo and friends
in any way it likes.

So with Ints you have [1, 3 .. 10] :: [Int] == [1, 3, 5, 7, 9]
but with Chars you get ['a', 'c' .. 'i'] :: [Char] == "acegi"
and with Floats you curiously get [1, 3 .. 10] :: [Float] == [1.0,
3.0, 5.0, 7.0, 9.0, 11.0]

On Mon, Apr 7, 2008 at 2:07 PM, PR Stanley <prstanley at ntlworld.com> wrote:
> At 12:28 07/04/2008, you wrote:
> > On Fri, Apr 4, 2008 at 10:49 PM, Andrew Coppin
> > <andrewcoppin at btinternet.com> wrote:
> > >  More to the point, the range y..z goes in steps of y-z. ;-)
> > [x,y..z] goes in steps of y-x ;-), [y..z] goes in steps of 1
> > (depending on the type).
> >
>         Could you elaborate please?


More information about the Haskell-Cafe mailing list