[Haskell-beginners] fromIntegral

Russ Abbott russ.abbott at gmail.com
Thu Sep 30 23:54:50 EDT 2010

In explaining fromIntegral, I want to say that it is really a collection of
overloaded functions:

Integer -> Double
Int -> Float

When GHC compiles a line of code with fromIntegral it in, it must decide at
compile time which of these overloaded functions to compile to.  This is in
contrast to saying that fromIngetral is a function of the type (Integral a,
Num b) => a -> b.  In reality there is no (single) function of the type
(Integral a, Num b) => a -> b because (among other things) every function
must map between actual types, but (Integral a, Num b) => a -> b does not
say which actual types are mapped between.

Is the preceding a reasonable thing to say?

If so, can I say the same sort of thing about constants like 1 and []? In
particular there is no single value []. Instead [] is a symbol which at
compile time must be compiled to the empty list of some particular type,
e.g., [Int].  There is no such Haskell value as [] :: [a] since [a] (as
type) is not an actual type. I want to say the same thing about 1, i.e.,
that there is no such Haskell value as 1 :: (Num t) => t. When the symbol 1
appears in a program, the compiler must decide during compilation whether it
is intended to be 1::Int or 1::Integer or 1::Double, etc.

-- Russ Abbott
  Professor, Computer Science
  California State University, Los Angeles

  Google voice: 424-242-USA0 (last character is zero)
  blog: http://russabbott.blogspot.com/
  vita:  http://sites.google.com/site/russabbott/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100930/55e36156/attachment.html

More information about the Beginners mailing list