Prob with numeric values

Janis Voigtlaender voigt@orchid.inf.tu-dresden.de
Thu, 23 May 2002 15:52:08 +0200


Jos Mistiaen wrote:

> (When I type inc 5::Int it does the job perfectly, because I explicitly say
> 5 is an Integer, but how can I tell the program 5 is an Int?????ithout
> saying it explicitly in the prompt)

You HAVE to tell the program that 5 is an Int, because there might be
other instances of your class, e.g.:

  class A a where
    inc::a->a

  instance A Int where
    inc a = a + 1

  instance A Float where
    inc a = a - 1

Then you get:

  Main> inc 5 :: Int
  6
  (18 reductions, 21 cells)

but:

  Main> inc 5 :: Float
  4.0
  (18 reductions, 26 cells)

So clearly the result depends on the type, which therefor cannot be
omitted.

Regards, Janis.


--
Janis Voigtlaender
http://wwwtcs.inf.tu-dresden.de/~voigt/
mailto:voigt@tcs.inf.tu-dresden.de