Re: Haskell-Cafe Digest, Vol 29, Issue 36

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Re: Haskell-Cafe Digest, Vol 29, Issue 36


Christian Maeder wrote:

> Jared Updike wrote:
> >
> >
> I still don't see, why it works for show but not for my_show.
> > On 1/12/06, [hidden email] <[hidden email]> 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.

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
[hidden email]