[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell-cafe
Subject:    [Haskell-cafe] Fwd: Uniplate + strict fields = fail. Why?
From:       Dmitry Astapov <dastapov () gmail ! com>
Date:       2009-09-30 17:58:50
Message-ID: 45047e50909301058y12874a32n30f694b1751e58a4 () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi,

I've been playing with generics in general (pardon the pun) and Uniplate in
particular, and found out that strict data fields somehow derail Uniplate.

Observe:
=== code ===

{-# LANGUAGE DeriveDataTypeable #-}
module Test where

import Data.Generics (Data(..),Typeable(..))
import Data.Generics.PlateData
import Data.ByteString
import Data.ByteString.Char8 as C


data Foo = Foo String deriving (Show, Data, Typeable)

tst1 = [ Foo "a", Foo "b" ]
test1 = [ show x | Foo x <- universeBi tst1 ]


-- *Test> test1
-- ["\"a\"","\"b\""]


data Bar = Bar ByteString deriving (Show, Data, Typeable)

tst2 = [ Bar (C.pack "a"), Bar (C.pack "b") ]

test2 = [ show x | Bar x <- universeBi tst2 ]


-- *Test> test2
-- *** Exception: Prelude.undefined
=== end of code ===

First, I thought that instance of Data for ByteString is somehow deficient,
but this is not the case.

If you change definition of Foo to "data Foo = Foo !String", you would get
the same error with "Prelude.undefined".

Since all fields in ByteString constructors are strict, I have no joy trying
to use it with Uniplate.

Howere, my type-foo is not strong enough to understand what's wrong. Could
someone give me a hint?

PS
ghc 6.10.4
uniplate 1.2.0.3
bytestring 0.9.1.4

PPS
Neil Mitchell is receiving a copy of this email

-- 
Dmitry Astapov

[Attachment #5 (text/html)]

Hi,<br><div class="gmail_quote"><br>I&#39;ve been playing with generics in general \
(pardon the pun) and Uniplate in particular, and found out that strict data fields \
somehow derail Uniplate.<br><br>Observe:<br>=== code ===<br>

<div>
<pre><span><span>{-# LANGUAGE DeriveDataTypeable \
#-}</span><br></span><span><span>module</span> <span>Test</span> \
<span>where</span><br></span><span><br> </span><span><span>import</span> \
<span>Data.Generics</span> \
<span>(</span><span>Data</span><span>(</span><span>..</span><span>),</span><span>Typeable</span><span>(</span><span>..</span><span>))</span><br>
 </span><span><span>import</span> \
<span>Data.Generics.PlateData</span><br></span><span><span>import</span> \
<span>Data.ByteString</span><br></span><span><span>import</span> \
<span>Data.ByteString.Char8</span> <span>as</span> <span>C</span><br>


</span><span><br></span><span><span>data</span> <span>Foo</span> <span>=</span> \
<span>Foo</span> <span>String</span> <span>deriving</span> \
<span>(</span><span>Show</span><span>,</span> <span>Data</span><span>,</span> \
<span>Typeable</span><span>)</span><br>


</span><span><span>tst1</span> <span>=</span> <span>[</span> <span>Foo</span> \
<span>&quot;a&quot;</span><span>,</span> <span>Foo</span> <span>&quot;b&quot;</span> \
<span>]</span><br> </span><span><span>test1</span> <span>=</span> <span>[</span> \
<span>show</span> <span>x</span> <span>|</span> <span>Foo</span> <span>x</span> \
<span>&lt;-</span> <span>universeBi</span> <span>tst1</span> <span>]</span><br>


</span><span><br></span><span><span>-- *Test&gt; \
test1</span><br></span><span><span>-- \
[&quot;\&quot;a\&quot;&quot;,&quot;\&quot;b\&quot;&quot;]</span><br> \
</span><span><br></span><span><br></span><span><span>data</span> <span>Bar</span> \
<span>=</span> <span>Bar</span> <span>ByteString</span> <span>deriving</span> \
<span>(</span><span>Show</span><span>,</span> <span>Data</span><span>,</span> \
<span>Typeable</span><span>)</span><br>


</span><span><span>tst2</span> <span>=</span> <span>[</span> <span>Bar</span> \
<span>(</span><span>C</span><span>.</span><span>pack</span> \
<span>&quot;a&quot;</span><span>),</span> <span>Bar</span> \
<span>(</span><span>C</span><span>.</span><span>pack</span> \
<span>&quot;b&quot;</span><span>)</span> <span>]</span><br>


</span><span><span>test2</span> <span>=</span> <span>[</span> <span>show</span> \
<span>x</span> <span>|</span> <span>Bar</span> <span>x</span> <span>&lt;-</span> \
<span>universeBi</span> <span>tst2</span> <span>]</span><br>


</span><span><br></span><span><span>-- *Test&gt; \
test2</span><br></span><span><span>-- *** Exception: \
Prelude.undefined</span><br></span>=== end of code ===<span><br> \
<br></span><span></span></pre></div>First, I thought that instance of Data for \
ByteString is somehow deficient, but this is not the case.<br><br>If you change \
definition of Foo to &quot;data Foo = Foo !String&quot;, you would get the same error \
with &quot;Prelude.undefined&quot;.<br>


<br>Since all fields in ByteString constructors are strict, I have no joy trying to \
use it with Uniplate.<br><br>Howere, my type-foo is not strong enough to understand \
what&#39;s wrong. Could someone give me a hint?<br><br>


PS<br>ghc 6.10.4<br>uniplate 1.2.0.3<br>bytestring 0.9.1.4<br \
clear="all"><br>PPS<br>Neil Mitchell is receiving a copy of this \
email<br></div><br>-- <br>Dmitry Astapov<br>



_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic