type equivalency

Andrew J Bromage andrew@bromage.org
Thu, 6 Jun 2002 13:07:50 +1000


G'day all.

On Wed, Jun 05, 2002 at 08:20:03PM -0500, Jon Cast wrote:

> I think you're confused about what the type declarations mean.  When
> you say
> 
> > sqrt :: Float -> Float
> 
> you're promising to operate over /all/ Floats.

That would be true of Haskell functions were constrained to be
total functions.  They are not.  Sqrt takes values of type Float,
but it just happens to be a partial function over that type.

> Unfortunately, Haskell
> doesn't allow {x :: Float | x >= 0} as a type, nor does it provide a
> positive-only floating point type.

One general rule of strongly-typed programming is:  A program is type
correct if it is accepted by my favourite type checker.  A corollary
is that what you call a type, I reserve the right to call a
precondition.

Cheers,
Andrew Bromage