[Haskell-beginners] data declaration using other type's names?

Patrick Redmond plredmond at gmail.com
Thu Jun 27 17:24:51 CEST 2013


Hey Haskellers,

I noticed that ghci lets me do this:

> data Foo = Int Int | Float
> :t Int
Int :: Int -> Foo
> :t Float
Float :: Foo
> :t Int 4
Int 4 :: Foo

It's confusing to have type constructors that use names of existing
types. It's not intuitive that the name "Int" could refer to two
different things, which brings me to:

> data Bar = Bar Int
> :t Bar
Bar :: Int -> Bar

Yay? I can have a simple type with one constructor named the same as the type.

Why is this allowed? Is it useful somehow?

--Patrick



More information about the Beginners mailing list