Note that there are some explanatory texts on larger screens.

plurals
  1. POExistentials and Scrap your Boilerplate
    text
    copied!<p>I'm writing a XML (de)serializer using Text.XML.Light and Scrap your Boilerplate (at <a href="http://github.com/finnsson/Text.XML.Generic" rel="nofollow noreferrer">http://github.com/finnsson/Text.XML.Generic</a>) and so far I got working code for "normal" ADTs but I'm stuck at deserializing existentials.</p> <p>I got the existential data type</p> <pre><code>data DataBox where DataBox :: (Show d, Eq d, Data d) =&gt; d -&gt; DataBox </code></pre> <p>and I'm trying to get this to compile</p> <pre><code>instance Data DataBox where gfoldl k z (DataBox d) = z DataBox `k` d gunfold k z c = k (z DataBox) -- not OK toConstr (DataBox d) = toConstr d dataTypeOf (DataBox d) = dataTypeOf d </code></pre> <p>but I can't figure out how to implement <code>gunfold</code> for <code>DataBox</code>.</p> <p>The error message is</p> <pre><code>Text/XML/Generic.hs:274:23: Ambiguous type variable `b' in the constraints: `Eq b' arising from a use of `DataBox' at Text/XML/Generic.hs:274:23-29 `Show b' arising from a use of `DataBox' at Text/XML/Generic.hs:274:23-29 `Data b' arising from a use of `k' at Text/XML/Generic.hs:274:18-30 Probable fix: add a type signature that fixes these type variable(s) </code></pre> <p>It's complaining about not being able to figure out the data type of <code>b</code>.</p> <p>I'm also trying to implement <code>dataCast1</code> and <code>dataCast2</code> but I think I can live without them (i.e. an incorrect implementation).</p> <p>I guess my questions are:</p> <ol> <li>Is it possible to combine existentials with Scrap your Boilerplate?</li> <li>If so: how do you implement gunfold for an existential data type?</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload