Hello Neil,<br><br><div class="gmail_quote">On Thu, Dec 11, 2008 at 09:49, Neil Mitchell <span dir="ltr">&lt;<a href="mailto:ndmitchell@gmail.com">ndmitchell@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Pedro,<br>
<div class="Ih2E3d"><br>
&gt;&gt; I&#39;m not sure there is a nice solution - reflection at the type level<br>
&gt;&gt; (using _|_ at the value level), combined with strictness at the value<br>
&gt;&gt; level, has limitations. It may be that the reflection machinery in SYB<br>
&gt;&gt; can be tweaked to either alert the user in advance (i.e. by getting<br>
&gt;&gt; the strictness of various fields), or providing some operation<br>
&gt;&gt; combining gmapQ and fromConstr which isn&#39;t strict. To see my use case<br>
&gt;&gt; take a look at &quot;contains&quot; in:<br>
&gt;&gt;<br>
&gt;&gt; <a href="http://www.cs.york.ac.uk/fp/darcs/uniplate/Data/Generics/PlateData.hs" target="_blank">http://www.cs.york.ac.uk/fp/darcs/uniplate/Data/Generics/PlateData.hs</a><br>
&gt;<br>
&gt; I&#39;m not sure there&#39;s an easy solution either. As you say, the problem here<br>
&gt; seems to be caused by the strictness. Getting the strictness of each field<br>
&gt; would require changes to the representation types and to the deriving<br>
&gt; mechanism.<br>
&gt;<br>
&gt; Would your problem be solved if you used fromConstrB instead of simply<br>
&gt; fromConstr and built an entirely determined (without bottoms) value?<br>
<br>
</div>I might be able to use fromConstrB, but it requires a lot more work -<br>
initialising lots of things and creating lots of dummy values. I&#39;ll<br>
look into it.</blockquote><div><br>Would this help?<br><br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex; font-family: courier new,monospace;" class="gmail_quote">
{-# LANGUAGE ScopedTypeVariables&nbsp; #-}<br>{-# LANGUAGE FlexibleContexts&nbsp;&nbsp;&nbsp;&nbsp; #-}<br><br>module Data.Generics.Builders (empty) where<br><br>import Data.Data<br>import Data.Generics.Aliases (extB)<br><br>-- | Construct the empty value for a datatype. For algebraic datatypes, the<br>
-- leftmost constructor is chosen.<br>empty :: forall a. Data a =&gt; a<br>empty = general <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `extB` char <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `extB` int<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `extB` integer<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `extB` float <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `extB` double where<br>&nbsp; -- Generic case<br>
&nbsp; general :: Data a =&gt; a<br>&nbsp; general = fromConstrB empty (indexConstr (dataTypeOf general) 1)<br>&nbsp; <br>&nbsp; -- Base cases<br>&nbsp; char&nbsp;&nbsp;&nbsp; = &#39;\NUL&#39;<br>&nbsp; int&nbsp;&nbsp;&nbsp;&nbsp; = 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :: Int<br>&nbsp; integer = 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :: Integer<br>&nbsp; float&nbsp;&nbsp; = 0.0&nbsp;&nbsp;&nbsp; :: Float<br>
&nbsp; double&nbsp; = 0.0&nbsp;&nbsp;&nbsp; :: Double<br></blockquote> <br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
<br>
I also note that the documentation for fromConstrB seems to have<br>
disappeared. See:<br>
<a href="http://haskell.org/ghc/docs/latest/html/libraries/syb/doc-index.html" target="_blank">http://haskell.org/ghc/docs/latest/html/libraries/syb/doc-index.html</a> -<br>
the entry is still there but the link is gone.</blockquote><div><br>fromConstrB is not in the syb package. It&#39;s in base4, in Data.Data: <a href="http://www.haskell.org/ghc/dist/stable/docs/libraries/base/Data-Data.html#v%3AfromConstrB">http://www.haskell.org/ghc/dist/stable/docs/libraries/base/Data-Data.html#v%3AfromConstrB</a><br>
<br><br>Thanks,<br>Pedro<br>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
<br>
(I&#39;m also aware that the Hoogle documentation for it is missing, but<br>
hope to fix that this weekend - I&#39;ve had issues trying to build<br>
things)<br>
<br>
Thanks<br>
<font color="#888888"><br>
Neil<br>
</font></blockquote></div><br>