[Haskell-cafe] No instance for (Constructor Main.D1MyData)
José Pedro Magalhães
jpm at cs.uu.nl
Tue Dec 10 16:34:49 UTC 2013
Hi Maarten,
On Tue, Dec 10, 2013 at 3:48 PM, Maarten Faddegon <
haskell-cafe at maartenfaddegon.nl> wrote:
> Dear list,
>
>
> -- | Meta-information (constructor names, etc.)
>> instance (GToonbaar a, Constructor c) => GToonbaar (M1 i c a) where
>>
>
This is not good; an instance of |Constructor c| will only be available
when your |M1 i c a| is
actually |M1 C c a| (so |i ~ C|). In the other cases (that is, when |i| is
either |D| or |S|), that
instance will not exist (there will be |Datatype| and |Selector| instances,
respectively).
You can find a generic show using GHC.Generics here:
http://hackage.haskell.org/package/generic-deriving-1.6.2/docs/src/Generics-Deriving-Show.html
>
>> -- | Sums: encode choice between constructors
>> instance (GToonbaar a, GToonbaar b) => GToonbaar (a :+: b) where
>> gtoon x = gtoon x
>>
>
This will cause your code to loop, btw.
>
>> When I try to compile the above, ghc emits the following error:
>
> No instance for (Constructor Main.D1MyData)
> arising from a use of `Main.$gdmtoon'
> Possible fix:
> add an instance declaration for (Constructor Main.D1MyData)
> In the expression: (Main.$gdmtoon)
> In an equation for `toon': toon = (Main.$gdmtoon)
> In the instance declaration for `Toonbaar MyData'
>
It's not the most beautiful of errors, but it does say that there is no
|Constructor|
instance for |D1MyData|, and |D1MyData| is the automatically generated
datatype
to encode the *datatype* meta-information for |MyData|.
Hope that helps,
Pedro
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20131210/2e452396/attachment.html>
More information about the Haskell-Cafe
mailing list