deriving Show for GADT?

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

deriving Show for GADT?

Norman Ramsey-2
I've got a fairly large GADT for which I wished to use
   deriving (Show)
but I got a mysterious error message:

Exp.hs:13:11:
    Can't make a derived instance of `Show (Exp a)'
      (`Exp' has non-Haskell-98 constructor(s))
    In the data type declaration for `Exp'


This is from GHC.  Does anybody know a compiler option or other trick
that will coax the compiler into producing a Show instance.
(I know I can write one by hand, but I'd rather not bother.)


Norman
_______________________________________________
Haskell mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell
Reply | Threaded
Open this post in threaded view
|

Re: deriving Show for GADT?

Ben Moseley
Unfortunately, this isn't supported at present.

--Ben

On 14 Apr 2009, at 05:28, Norman Ramsey wrote:

> I've got a fairly large GADT for which I wished to use
>   deriving (Show)
> but I got a mysterious error message:
>
> Exp.hs:13:11:
>    Can't make a derived instance of `Show (Exp a)'
>      (`Exp' has non-Haskell-98 constructor(s))
>    In the data type declaration for `Exp'
>
>
> This is from GHC.  Does anybody know a compiler option or other trick
> that will coax the compiler into producing a Show instance.
> (I know I can write one by hand, but I'd rather not bother.)
>
>
> Norman
> _______________________________________________
> Haskell mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell

_______________________________________________
Haskell mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell
Reply | Threaded
Open this post in threaded view
|

Re: deriving Show for GADT?

Ryan Ingram
In reply to this post by Norman Ramsey-2
You might be able to write some Template Haskell to derive the Show instance.

It's a bit tricky, because there are some types which can't have Show
derived, such as:

data Foo where
    Broken :: a -> Foo

What should
    show (Broken id)
do?

  -- ryan

On Mon, Apr 13, 2009 at 9:28 PM, Norman Ramsey <[hidden email]> wrote:

> I've got a fairly large GADT for which I wished to use
>   deriving (Show)
> but I got a mysterious error message:
>
> Exp.hs:13:11:
>    Can't make a derived instance of `Show (Exp a)'
>      (`Exp' has non-Haskell-98 constructor(s))
>    In the data type declaration for `Exp'
>
>
> This is from GHC.  Does anybody know a compiler option or other trick
> that will coax the compiler into producing a Show instance.
> (I know I can write one by hand, but I'd rather not bother.)
>
>
> Norman
> _______________________________________________
> Haskell mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell
>
_______________________________________________
Haskell mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell
Reply | Threaded
Open this post in threaded view
|

Re: deriving Show for GADT?

Edward Kmett-2
I seem to recall Matt Morrow having some code lying around for automatically generating such instances using haskell-src-exts. I wonder how hard it would be to adapt to Template Haskell.
-Edward Kmett

 
On Tue, Apr 14, 2009 at 2:03 AM, Ryan Ingram <[hidden email]> wrote:
You might be able to write some Template Haskell to derive the Show instance.

It's a bit tricky, because there are some types which can't have Show
derived, such as:

data Foo where
   Broken :: a -> Foo

What should
   show (Broken id)
do?

 -- ryan

On Mon, Apr 13, 2009 at 9:28 PM, Norman Ramsey <[hidden email]> wrote:
> I've got a fairly large GADT for which I wished to use
>   deriving (Show)
> but I got a mysterious error message:
>
> Exp.hs:13:11:
>    Can't make a derived instance of `Show (Exp a)'
>      (`Exp' has non-Haskell-98 constructor(s))
>    In the data type declaration for `Exp'
>
>
> This is from GHC.  Does anybody know a compiler option or other trick
> that will coax the compiler into producing a Show instance.
> (I know I can write one by hand, but I'd rather not bother.)
>
>
> Norman
> _______________________________________________
> Haskell mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell
>
_______________________________________________
Haskell mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell


_______________________________________________
Haskell mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell
Reply | Threaded
Open this post in threaded view
|

Re: deriving Show for GADT?

Dominic Steinitz
In reply to this post by Norman Ramsey-2
Norman Ramsey <nr <at> cs.tufts.edu> writes:

>
> I've got a fairly large GADT for which I wished to use
>    deriving (Show)
You will have to write one by hand. I tend to use Text.Pretty and then the
output is much more readable. It doesn't take long even for a what I would
consider a large GADT.

_______________________________________________
Haskell mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell