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, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 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, and
     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.  
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to