# [Haskell] Re: Implicit type of numeric constants

Christian Sievers sievers at math2.nat.tu-bs.de
Thu Sep 21 14:36:06 EDT 2006

```Robert Stroud wrote:

> Thanks for your explanation - this is beginning to make more sense to
> me. However, I'm not finding it easy to follow the Haskell language
> manual, and understand how the rules apply, so please could you
> confirm that the following reasoning is correct...
>
> Firstly, am I right in thinking that "k = 2" is a simple pattern
> binding?

Yes.

>          The syntax for a top-level declaration doesn't seem to
> include the possibility of declaring a variable, and there doesn't
> seem to be an explicit syntax for pattern.

I couldn't find it easily either, but eventually I found it:
section 3.17.1.

The rest of your reasoning seems right, too.

> OK - so far so good I hope. What I don't understand though is why the
> monomorphism restriction is necessary for the case of a simple
> constant declaration. The language manual gives two motivations,
> neither of which seems to apply. The first reason is to do with
> preventing computations being unexpectedly repeated, but there is no
> computation involved here, since k is defined as a constant. The
> second reason is to prevent ambiguity, but the example involves a non-
> simple binding. So why is it necessary to give a named constant a
> monomorphic type, when the unnamed constant has a polymorphic type?

I think it would make the language irregular, and you would probably
also want slightly more complex constants, and then where to draw the line?
What would you think of

a = 2
b = a
c = -a
d = a+1
e = 2^16
f = 1/7
g = product [1..10]

What maybe interesting to you is that when I read the claim that the k in the
let clause was polymorphic, I didn't think "no, it isn't", but rather
"oh, is it?", and then tried it.  And the first result of trying to explain
that what getting more confused.  I think you don't have to know exactly all
the things I described in my yesterday's mail - I didn't know them yesterday
morning either.  All you have to know is that when you get such errors, you
can fix them with an explicit type signature.
But if you wonder what a strange language that is, continue to ask, it's
a bit complex, but well defined and quite regular.
(I think the haskell-cafe mailing list might be more apprpriate.)

All the best
Christian
```

More information about the Haskell mailing list