[Haskell-cafe] resolving missing class instances @ compile time

Bernard Pope bjpop at cs.mu.OZ.AU
Wed May 4 20:58:27 EDT 2005


On Wed, 2005-05-04 at 17:18 -0700, Greg Buchholz wrote:
>     Here's a little quirk I ran into recently.  While making a little
> vector data type in class Num (code below), I didn't implement an
> instance of "fromInteger" (thinking I didn't need it).  Well as you can
> probably guess, it turns out I did need it, and subsequently got a run
> time exception.  Which surprised me a little, since it seems like it
> could have been caught at compile time.  (Although I did ignore a
> warning).  This has probably been answered a thousand times, but could
> someone point me in the direction of documentation explaining why it
> compiled?
> 
> Thanks,
> 
> Greg Buchholz

Hi Greg,

Perhaps this section of the report might help:

>From Section "4.3.2 Instance Declarations" in the Haskell Report:

   http://www.haskell.org/onlinereport/decls.html#instance-decls

"If no binding is given for some class method then the corresponding
default class method in the class declaration is used (if present); if
such a default does not exist then the class method of this instance is
bound to undefined and no compile-time error results."

Cheers,
Bernie.



More information about the Haskell-Cafe mailing list