Auto generated instance codes through 'deriving'

Jong Keun Na jongkn@microsoft.com
Mon, 10 Feb 2003 11:48:10 +0900


This is a multi-part message in MIME format.

--------------InterScan_NT_MIME_Boundary
Content-Type: multipart/alternative;
	boundary="----_=_NextPart_001_01C2D0AE.D93B6870"

------_=_NextPart_001_01C2D0AE.D93B6870
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

The following code snippet not works correctly.

=20

>data Obj =3D Obj {_id, p1, p2::Int} deriving (Show, Read)

=20

>showObj :: Obj -> String

>showObj o =3D show o

=20

>main =3D do print (showObj (read "Obj {_id=3D1,p1=3D10,p2=3D20}"))

>              return ()

=20

The reason is because I used the property name with underscore char like
"_id".

Looking into auto generated class codes and seeing they show it should
encompass identifiers with special characters with parenthesis, so I
tried "Obj {(_id)=3D1,p1=3D10,p2=3D20}" as argument of read func. But, =
the
result is same, parse error.

=20

Is this problem by-design or bug? Or Am I missing any point?

=20

Thanks,

/JongKeun

=20

=20

-----Original Message-----
From: Simon Peyton-Jones=20
Sent: Friday, February 07, 2003 5:41 PM
To: Jong Keun Na; haskell-cafe@haskell.org
Subject: RE: Auto generated instance codes through 'deriving'

=20

Try -ddump-deriv

=20
http://haskell.cs.yale.edu/ghc/docs/latest/html/users_guide/options-debu
gging.html#DUMPING-OUTPUT

=20

Simon

=20

-----Original Message-----
From: Jong Keun Na [mailto:jongkn@microsoft.com]=20
Sent: 07 February 2003 06:15
To: haskell-cafe@haskell.org
Subject: Auto generated instance codes through 'deriving'

=20

Hello folks,

Is there any method with which I can see instance's codes generated
automatically by using 'deriving' keyword in GHC?

I'm curious in how GHC generates 'Read' class's instance code for
user-defined data type.

Any help will be great appreciated.

/JongKeun


------_=_NextPart_001_01C2D0AE.D93B6870
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>

<head>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">


<meta name=3DGenerator content=3D"Microsoft Word 10 (filtered)">
<title>Auto generated instance codes through 'deriving'</title>

<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:Batang;
	panose-1:2 3 6 0 0 1 1 1 1 1;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
	{font-family:Batang;
	panose-1:2 3 6 0 0 1 1 1 1 1;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;}
p
	{margin-right:0cm;
	margin-left:0cm;
	font-size:12.0pt;
	font-family:"Times New Roman";}
span.emailstyle18
	{font-family:Arial;
	color:navy;}
span.EmailStyle19
	{font-family:Tahoma;
	color:blue;
	font-weight:normal;
	font-style:normal;
	text-decoration:none none;}
@page Section1
	{size:595.3pt 841.9pt;
	margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
	{page:Section1;}
-->
</style>

</head>

<body lang=3DKO link=3Dblue vlink=3Dpurple>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 color=3Dblue face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma;color:blue'><!-- Converted =
from text/rtf format -->The
following code snippet not works correctly.</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dblue face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma;color:blue'>&nbsp;</span></f=
ont></p>

<p class=3DMsoNormal><font size=3D2 color=3Dblue face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma;color:blue'>&gt;data Obj =
=3D Obj {_id,
p1, p2::Int} deriving (Show, Read)</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dblue face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma;color:blue'>&nbsp;</span></f=
ont></p>

<p class=3DMsoNormal><font size=3D2 color=3Dblue face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma;color:blue'>&gt;showObj :: =
Obj -&gt;
String</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dblue face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma;color:blue'>&gt;showObj o =
=3D show o</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dblue face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma;color:blue'>&nbsp;</span></f=
ont></p>

<p class=3DMsoNormal><font size=3D2 color=3Dblue face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma;color:blue'>&gt;main =3D do =
print (showObj
(read &quot;Obj {_id=3D1,p1=3D10,p2=3D20}&quot;))</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dblue face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma;color:blue'>&gt;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
return ()</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dblue face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma;color:blue'>&nbsp;</span></f=
ont></p>

<p class=3DMsoNormal><font size=3D2 color=3Dblue face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma;color:blue'>The reason is =
because I
used the property name with underscore char like =
&#8220;_id&#8221;.</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dblue face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma;color:blue'>Looking into =
auto
generated class codes and seeing they show it should encompass =
identifiers with
special characters with parenthesis, so I tried &quot;Obj =
{(_id)=3D1,p1=3D10,p2=3D20}&quot;
as argument of read func. But, the result is same, parse =
error.</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dblue face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma;color:blue'>&nbsp;</span></f=
ont></p>

<p class=3DMsoNormal><font size=3D2 color=3Dblue face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma;color:blue'>Is this problem
by-design or bug? Or Am I missing any point?</span></font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dblue face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma;color:blue'>&nbsp;</span></f=
ont></p>

<p class=3DMsoNormal><font size=3D2 color=3Dblue face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma;color:blue'>Thanks,</span></=
font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dblue face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma;color:blue'>/JongKeun</span>=
</font></p>

<p class=3DMsoNormal><font size=3D2 color=3Dblue face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma;color:blue'>&nbsp;</span></f=
ont></p>

<p class=3DMsoNormal><font size=3D2 color=3Dblue face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma;color:blue'>&nbsp;</span></f=
ont></p>

<p class=3DMsoNormal style=3D'margin-left:39.95pt'><font size=3D2 =
face=3DTahoma><span
lang=3DEN-US style=3D'font-size:10.0pt;font-family:Tahoma'>-----Original
Message-----<br>
<b><span style=3D'font-weight:bold'>From:</span></b> Simon Peyton-Jones =
<br>
<b><span style=3D'font-weight:bold'>Sent:</span></b> Friday, February =
07, 2003
5:41 PM<br>
<b><span style=3D'font-weight:bold'>To:</span></b> Jong Keun Na;
haskell-cafe@haskell.org<br>
<b><span style=3D'font-weight:bold'>Subject:</span></b> RE: Auto =
generated
instance codes through 'deriving'</span></font></p>

<p class=3DMsoNormal style=3D'margin-left:39.95pt'><font size=3D3
face=3D"Times New Roman"><span lang=3DEN-US =
style=3D'font-size:12.0pt'>&nbsp;</span></font></p>

<p class=3DMsoNormal style=3D'margin-left:39.95pt'><font size=3D2 =
color=3Dnavy
face=3DArial><span lang=3DEN-GB =
style=3D'font-size:10.0pt;font-family:Arial;
color:navy'>Try -ddump-deriv</span></font></p>

<p class=3DMsoNormal style=3D'margin-left:39.95pt'><font size=3D2 =
color=3Dnavy
face=3DArial><span lang=3DEN-GB =
style=3D'font-size:10.0pt;font-family:Arial;
color:navy'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;
http://haskell.cs.yale.edu/ghc/docs/latest/html/users_guide/options-debug=
ging.html#DUMPING-OUTPUT</span></font></p>

<p class=3DMsoNormal style=3D'margin-left:39.95pt'><font size=3D2 =
color=3Dnavy
face=3DArial><span lang=3DEN-GB =
style=3D'font-size:10.0pt;font-family:Arial;
color:navy'>&nbsp;</span></font></p>

<p class=3DMsoNormal style=3D'margin-left:39.95pt'><font size=3D2 =
color=3Dnavy
face=3DArial><span lang=3DEN-GB =
style=3D'font-size:10.0pt;font-family:Arial;
color:navy'>Simon</span></font></p>

<p class=3DMsoNormal style=3D'margin-left:39.95pt'><font size=3D2 =
color=3Dnavy
face=3DArial><span lang=3DEN-GB =
style=3D'font-size:10.0pt;font-family:Arial;
color:navy'>&nbsp;</span></font></p>

<div style=3D'border:none;border-left:solid blue 1.5pt;padding:0cm 0cm =
0cm 4.0pt'>

<p class=3DMsoNormal style=3D'margin-left:39.95pt'><font size=3D2 =
face=3DTahoma><span
lang=3DEN-US style=3D'font-size:10.0pt;font-family:Tahoma'>-----Original
Message-----<br>
<b><span style=3D'font-weight:bold'>From:</span></b> Jong Keun Na
[mailto:jongkn@microsoft.com] <br>
<b><span style=3D'font-weight:bold'>Sent:</span></b> 07 February 2003 =
06:15<br>
<b><span style=3D'font-weight:bold'>To:</span></b> =
haskell-cafe@haskell.org<br>
<b><span style=3D'font-weight:bold'>Subject:</span></b> Auto generated =
instance
codes through 'deriving'</span></font></p>

<p class=3DMsoNormal style=3D'margin-left:39.95pt'><font size=3D3
face=3D"Times New Roman"><span lang=3DEN-GB =
style=3D'font-size:12.0pt'>&nbsp;</span></font></p>

<p style=3D'margin-left:39.95pt'><font size=3D2 face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma'>Hello =
folks,</span></font></p>

<p style=3D'margin-left:39.95pt'><font size=3D2 face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma'>Is there any =
method</span></font><span
lang=3DEN-US> </span><font size=3D2 face=3DTahoma><span lang=3DEN-US =
style=3D'font-size:
10.0pt;font-family:Tahoma'>with which I can see</span></font><span =
lang=3DEN-US> </span><font
size=3D2 face=3DTahoma><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Tahoma'>instance&#8217;s</span></fo=
nt><span
lang=3DEN-US> </span><font size=3D2 face=3DTahoma><span lang=3DEN-US =
style=3D'font-size:
10.0pt;font-family:Tahoma'>codes</span></font><span lang=3DEN-US> =
</span><font
size=3D2 face=3DTahoma><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Tahoma'>generated
automatically</span></font><span lang=3DEN-US> </span><font size=3D2 =
face=3DTahoma><span
lang=3DEN-US style=3D'font-size:10.0pt;font-family:Tahoma'>by =
using</span></font><span
lang=3DEN-US> </span><font size=3D2 face=3DTahoma><span lang=3DEN-US =
style=3D'font-size:
10.0pt;font-family:Tahoma'>&#8216;<b><span =
style=3D'font-weight:bold'>deriving&#8217;</span></b>
keyword in GHC?</span></font></p>

<p style=3D'margin-left:39.95pt'><font size=3D2 face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma'>I&#8217;m curious in how =
GHC
generates</span></font><span lang=3DEN-US> </span><font size=3D2 =
face=3DTahoma><span
lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Tahoma'>&#8216;<b><span
style=3D'font-weight:bold'>Read&#8217;</span></b></span></font><span =
lang=3DEN-US> </span><font
size=3D2 face=3DTahoma><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Tahoma'>class&#8217;s</span></font>=
<span
lang=3DEN-US> </span><font size=3D2 face=3DTahoma><span lang=3DEN-US =
style=3D'font-size:
10.0pt;font-family:Tahoma'>instance code for</span></font><span =
lang=3DEN-US> </span><font
size=3D2 face=3DTahoma><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Tahoma'>user-defined</span></font><=
span
lang=3DEN-US> </span><font size=3D2 face=3DTahoma><span lang=3DEN-US =
style=3D'font-size:
10.0pt;font-family:Tahoma'>data type.</span></font></p>

<p style=3D'margin-left:39.95pt'><font size=3D2 face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma'>Any</span></font><span =
lang=3DEN-US> </span><font
size=3D2 face=3DTahoma><span lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Tahoma'>help
will be</span></font><span lang=3DEN-US> </span><font size=3D2 =
face=3DTahoma><span
lang=3DEN-US =
style=3D'font-size:10.0pt;font-family:Tahoma'>great</span></font><span
lang=3DEN-US> </span><font size=3D2 face=3DTahoma><span lang=3DEN-US =
style=3D'font-size:
10.0pt;font-family:Tahoma'>appreciated.</span></font></p>

<p style=3D'margin-left:39.95pt'><font size=3D2 face=3DTahoma><span =
lang=3DEN-US
style=3D'font-size:10.0pt;font-family:Tahoma'>/JongKeun</span></font></p>=


</div>

</div>

</body>

</html>

------_=_NextPart_001_01C2D0AE.D93B6870--

--------------InterScan_NT_MIME_Boundary--