<div>Hi all,<br>
<br>
You are talking about parsing and data type, so I want to ask you a
question relating to my data type. I have a data types and a function
as follows: <br>
<br>
\begin{code}<br>
<br>
data Type a = C1 <br>
&nbsp;&nbsp;&nbsp; {&nbsp; x :: [String]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,y :: Type a} <br>
&nbsp;&nbsp;&nbsp; | C2 {x1 :: String} <br>
&nbsp;&nbsp;&nbsp; | C3 {y1 :: Bool} deriving Show <br>
<br>
showType :: Type a -&gt; String<br>
showType (C2 a) = show a<br>
showType (C3 a) = show a<br>
showType (C1 a b) = show &quot;(&quot; ++ (show a) ++ (showType b) ++ (show &quot;)&quot;)<br>
<br>
r1 = C1 {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = [&quot;x&quot;,&quot;y&quot;] <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , y = C2{x1 = &quot;x^2 + y^2 &lt; 20&quot;}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
<br>
r2=C3{y1=False}<br>
<br>
r3=C2{x1=&quot;x+y=z&quot;}<br>
<br>
\end{code}<br>
<br>
--Result:<br>
<br>
Main&gt;showType r1<br>
<br>
&quot;\&quot;(\&quot;[\&quot;x\&quot;,\&quot;y\&quot;]\&quot;x^2 + y^2 &lt; 20\&quot;\&quot;)\&quot;&quot;<br>
<br>
Main&gt;showType r2<br>
&quot;False&quot;<br>
<br>
Main&gt;showType r3<br>
&quot;\&quot;x+y=z\&quot;&quot;<br>
<br>
Now, I want to write a function to see the result in its original type, for example :<br>
input: &quot;False&quot;<br>
output: False<br>
<br>
input:&quot;\&quot;x+y=z\&quot;&quot;<br>
output:&quot;x+y=z&quot;<br>
<br>
input:&quot;\&quot;(\&quot;[\&quot;x\&quot;,\&quot;y\&quot;]\&quot;x^2 + y^2 &lt; 20\&quot;\&quot;)\&quot;&quot;<br>
output:([&quot;x&quot;,&quot;y&quot;]x^2 + y^2 &lt; 20&quot;)<br>
<br>
So, how I should write the function ? Do you have any idea about this ? Thanks.<br>
<br>
<br>&nbsp;
From: <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:oleg@pobox.com">oleg@pobox.com</a> &lt;<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:oleg@pobox.com">oleg@pobox.com</a>

&gt;<br>
Date: Oct 16, 2005 8:50 PM<br>
Subject: [Haskell-cafe] Generic parser without GADTs<br>
To: <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:haskell-cafe@haskell.org">haskell-cafe@haskell.org</a><br>
Cc: <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:ralf@informatik.uni-bonn.de">ralf@informatik.uni-bonn.de</a><br>
<br>
<br>
<br>
Also inspired by Ralf Hinze's post, I thought of removing GADTs from<br>
that code. The result is Haskell98! code, which works well in<br>
Hugs. The code seems to be a bit simpler too. Like the original code,<br>
the function 'parseAny' correctly discriminates between the list of<br>
characters (i.e., strings) and the list of other things.<br>
<br>
{-- Haskell98! --}<br>
<br>
class Type a where<br>
 &nbsp;parse :: ReadS a<br>
<br>
<br>
 &gt; hugs /tmp/h.hs<br>
 &nbsp;Haskell 98 mode: Restart with command line option -98 to enable extensions<br>
<br>
 &nbsp;Main&gt; parseAny &quot;4711&quot;<br>
 &nbsp;[(ValInt 4711,&quot;&quot;)]<br>
 &nbsp;Main&gt; parseAny &quot;\&quot;4711\&quot;&quot;<br>
 &nbsp;[(ValString &quot;4711&quot;,&quot;&quot;)]<br>
 &nbsp;Main&gt; parseAny &quot;[4711, 0]&quot;<br>
 &nbsp;[(ValList [ValInt 4711,ValInt 0],&quot;&quot;)]<br>
 &nbsp;Main&gt; parseAny &quot;[4711, 'a']&quot;<br>
 &nbsp;[(ValList [ValInt 4711,ValChar 'a'],&quot;&quot;)]<br>
 &nbsp;Main&gt; parseAny &quot;[\&quot;hello world\&quot;] x&quot;<br>
 &nbsp;[(ValList [ValString &quot;hello world&quot;],&quot; x&quot;)]<br>
______________________________
<div id="mb_0">_________________<br>Haskell-Cafe mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">

http://www.haskell.org/mailman/listinfo/haskell-cafe</a></div>
</div>
<span class="q">
</span>