[Haskell-beginners] binding vs. parameter passing

James Jones jejones3141 at gmail.com
Tue Jul 23 02:29:30 UTC 2019


One problem in *Programming Haskell from First Principles* confuses me. (So
far.)

It's one where you start with the declaration and binding

i :: Num a => a
i = 1

(which of course works because Num a => a is the type of 1) and then change
the declaration to

i :: a

and first try to predict and then see what happens. It fails, with ghci
suggesting that you put the Num a => back. That seemed reasonable at first,
but then I considered this:

   - id has type a -> a, and if you try to evaluate id 1 it works without
   complaint.
   - In all the work I've done on compilers, parameter passing has
   effectively been assignment of actual parameters to the corresponding
   formal parameters. In Haskell, that might mean passing along the
   appropriate thunk, but the principle is the same, isn't it?

So, if I can't bind 1 to i which is declared to have type a, why can I
successfully pass 1 to id?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20190722/52efee62/attachment.html>


More information about the Beginners mailing list