:t 2^5000

Sigbjorn Finne sof@galois.com
Tue, 22 Jan 2002 13:22:19 -0800


Because the term has an ambiguous type -- the
type of (^) is

  (^) :: (Num a, Integral b) => a -> b -> a

and you supplied it with two (overloaded) numeric
literals, causing the following type to be inferred:

  ((^) 2 5000) :: (Integral b, Num a) => a

Haskell's defaulting mechanism allows an implementation
to discharge/remove 'Num-like' predicates from the
context of an ambiguous type, which is why when you come
to evaluate the term, both the '2' and '5000' are defaulted
to be of type Integer (at least by default in Haskell 98) & you
don't get to see ambiguity complaints.

See Section 10.4 of the Haskell tutorial
( http://www.haskell.org/tutorial/numbers.html ) + Section
4.3.4 of the Haskell report for more.

hth
--sigbjorn

----- Original Message -----
From: "Hal Daume III" <hdaume@ISI.EDU>
To: "Sigbjorn Finne" <sof@galois.com>
Cc: <hugs-bugs@haskell.org>
Sent: Tuesday, January 22, 2002 12:53
Subject: Re: :t 2^5000


> That wasn't really my concern.  My concern is why there are any type
> constraints on "a" even though there is no "a" in the type.
>
>  - Hal
>
> --
> Hal Daume III
>
>  "Computer science is no more about computers    | hdaume@isi.edu
>   than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume
>
> On Tue, 22 Jan 2002, Sigbjorn Finne wrote:
>
> > Hi,
> >
> > it is an advertised feature of Hugs' :type command to
> > display the most general type (see the user's manual).
> >
> > Giving the user control (via an option toggle) of whether
> > or not to use the 'defaults' to constrain the type returned
> > by :type, sounds reasonable. Unless someone puts forward
> > good reasons not to, I'll add support for this.
> >
> > --sigbjorn
> >
> > ----- Original Message -----
> > From: "Hal Daume III" <hdaume@ISI.EDU>
> > To: <hugs-bugs@haskell.org>
> > Sent: Tuesday, January 22, 2002 10:08
> > Subject: :t 2^5000
> >
> >
> > > if you enter :t 2^5000 in hugs, it gives:
> > >
> > > 2 ^ 5000 :: (Integral a, Num b) => b
> > >
> > > which is obviously wrong (since a appears nowhere), but it's also
obvious
> > > why it does this.  any chance this'll be fixed?
> > >
> > >  - hal
> > >
> > > --
> > > Hal Daume III
> > >
> > >  "Computer science is no more about computers    | hdaume@isi.edu
> > >   than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume
> > >
> > >
> > > _______________________________________________
> > > Hugs-Bugs mailing list
> > > Hugs-Bugs@haskell.org
> > > http://www.haskell.org/mailman/listinfo/hugs-bugs
> >