[Haskell] Re: Records

Ralf Lammel Ralf.Lammel at microsoft.com
Mon Nov 28 13:11:01 EST 2005

Good questions.

You can't have a polymorphic typecase like "`extQ` (show :: Show a => a
-> String )" because that's not really a *type*case. It is too
You can have a polymorphic typecase like "`extQ` ( lshow :: [ a ] ->
String )" because that's covered by the SYB2 paper; you need ext1Q
(extQ1, depending on version).

With SYB3, the second case is easier; it's just an instance.
The first case ... still doesn't work ... this time for reasons of the
class system. The type system doesn't allow to write one "default"
instance for the case that a certain constraint is satisfiable (here:
Show a) and to have yet another "default" instance to kick in
*otherwise* to the SYB version. 

It would be great to have typeclass case to deal with this issue.
Questions asking for typeclass case pop every now and then.

The idea of the example is that you would need to define your own
generic show function from scratch. The limitation of SYB1/SYB2 is that
you would hit a closed-world-assumption. That's why SYB3! It allows you
to add instances to the new generic show, as you go. Because of the lack
of typeclass case, you still wouldn't be able to use the normal Prelude
show function as default. You can use it instance-per-instance, by
adopting each (attractive) show instances to be become instance of the
new generic show function. However, you need to clone code because you
probably want to re-tie the recursive knot in the new generic function.

SYB3 is shipped separately, please use the distribution you pointed to.
Simon PJ and I are still undecided regarding the modalities for adding
SYB3 to the GHC libraries. Basically, we don't like the idea of having
two libraries; SYB3 is more powerful but the combinator types are
somewhat more complicated. However, using the separate SYB3 distribution
is safe because it comes with TH support and a standalone mini SYB


> -----Original Message-----
> From: haskell-bounces at haskell.org [mailto:haskell-bounces at haskell.org]

> On Behalf Of Johannes Waldmann
> Sent: Monday, November 28, 2005 7:33 AM
> To: haskell at haskell.org
> Subject: [Haskell] Data.Generics question
> Dear all, in Data.Generics.Text
> http://cvs.haskell.org/cgi-
> bin/cvsweb.cgi/fptools/libraries/base/Data/Generics/Text.hs?rev=1.10
> I find this nice example
> gshow = ( \t ->
>                 "("
>              ++ showConstr (toConstr t)
>              ++ concat (gmapQ ((++) " " . gshow) t)
>              ++ ")"
>         ) `extQ` (show :: String -> String)
> but I couldn't figure out how to use this to declare a useful show 
> instance. I would need something like
>        `extQ` (show :: Show a => a -> String )
> i. e. use Show instance if available, or
>        `extQ` ( lshow :: [ a ] -> String )
> i. e. use another function if argument type is a list type
> BTW: I guess the above is related to
> http://homepages.cwi.nl/~ralf/syb3/
> Do the current (6.4) ghc compiler/libraries correspond to what's in 
> that paper?
> --
> -- Johannes Waldmann -- Tel/Fax (0341) 3076 6479/80 --
> ---- http://www.imn.htwk-leipzig.de/~waldmann/ -------
> _______________________________________________
> Haskell mailing list
> Haskell at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell

More information about the Haskell mailing list