[Haskell-cafe] Re: Haskell-Cafe Digest, Vol 29, Issue 36

Jeff.Harper at handheld.com Jeff.Harper at handheld.com
Fri Jan 13 14:10:15 EST 2006

Christian Maeder wrote:
> Jared Updike wrote:
> > http://www.haskell.org/onlinereport/decls.html#default-decls
> > http://www.haskell.org/tutorial/numbers.html#sect10.4
> I still don't see, why it works for show but not for my_show.
> > On 1/12/06, Jeff.Harper at handheld.com <Jeff.Harper at handheld.com> wrote:
> [...]
> >> class (Show a) => My_show a where
> >>    my_show :: a -> String
> If I let this be
>    class My_show a where
>        my_show :: a -> String
> >> instance My_show Int where
> >>    my_show a = show a ++ " :: Int"
> >>
> >> instance My_show Integer where
> >>    my_show a = show a ++ " :: Integer"
> What is the difference to the builtin Show class?

I was wondering the same thing myself.  Then, I reread the online Haskell 
report link. 

>From http://www.haskell.org/onlinereport/decls.html#default-decls:
where n>=0, and each ti must be a type for which Num ti holds. In 
situations where an ambiguous type is discovered, an ambiguous type 
variable, v, is defaultable if: 
     o v appears only in constraints of the form C v, where C is a class, 
     o at least one of these classes is a numeric class, (that is, Num or 
a subclass of Num), and 
     o all of these classes are defined in the Prelude or a standard 
library (Figures 6.2--6.3, pages -- show the numeric classes, and Figure 
6.1, page , shows the classes defined in the Prelude.) 

Notice the last bullet item.  class Show is part of the Prelude.  However, 
class My_show is not part of the prelude.  AS far as I can tell, that's 
the only reason "my_show 1" produces errors while "show 1" is okay. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org//pipermail/haskell-cafe/attachments/20060113/4e3c9028/attachment.htm

More information about the Haskell-Cafe mailing list