[Haskell-beginners] beginner's type error

Brent Yorgey byorgey at seas.upenn.edu
Sat Mar 28 08:39:55 EDT 2009


On Fri, Mar 27, 2009 at 07:44:05PM +0000, Ivan Moore wrote:
> Many thanks for the fantastic answers.
> 
> I have a question related to your answer
> 
> > The reason (which is a bit confusing) is that it typechecks just
> > fine---if there *were* a type which is an instance of both Integral
> > and Floating (and I guess round needs RealFrac as well), n could have
> > that type.  There isn't such a type in the standard libraries, but in
> > theory you could make up your own type which is an instance of both.
> 
> If there were such a type, could "10" have that type and then would my
> problem have not existed? (in which case, why doesn't it!?)
> (an answer of - "ask again when you've used the language a bit more"
> would be perfectly fine if it requires a lot
> more understanding of the language to understand the answer than a
> newbie like me has - I'm just curious)
> 

If there were such a type, and if it were one of the types to which
ghci was allowed to default, then you would not have had a problem.
But if you look at the methods of the Integral and Floating classes,
you will see that such a type would likely be silly.  You can't really
have a type which is simultaneously Integral (i.e. whole numbers, with
no fractional part) and Floating (i.e. floating point numbers which
can be divided, square rooted, etc.).  To have a type be an instance
of both would require a radical reinterpretation of what these type
classes mean.

-Brent


More information about the Beginners mailing list