Options | Runtime | Use Show instance for results -- turned off is surprisingly unreliable
Anthony Clayden <[email protected]> Wed, 22 Sep 2021 00:33:02 +1200
| Newsgroups | gmane.comp.lang.haskell.hugs.bugs |
|---|---|
| Message-ID | <CABU_mxgdaa=A185ywMJUjuR+qm9ADwGkqtggU7_wtFzUEVFWNA@mail.gmail.com> |
--===============2949879067361515022== Content-Type: multipart/alternative; boundary="000000000000aeaae605cc809993" --000000000000aeaae605cc809993 Content-Type: text/plain; charset="UTF-8" I usually have 'Use Show instance' switched off (aka use 'built-in printer'), so I can see (at least in crude form) imported or 'system' datatypes that don't have show instances/also it's a bit more revealing if I get exceptions. I have a datatype: > data Tree a = Empty > | Leaf a > | Node (Tree a) a (Tree a) > deriving (Eq, Show, Read) For results of expressions that were `Node`s, the built-in printer just ignored the first field. (`show`/print of those values works fine.) > FoldableTree> myTree <> fdmap toUpper myTree > Node 'c' Empty > FoldableTree> print $ myTree <> fdmap toUpper myTree > Node (Node Empty 'A' (Node Empty 'C' (Leaf 'a'))) 'c' Empty Most disconcerting until I realised what was going on. (Of course I don't expect the built-in printer to produce pretty output). AntC --000000000000aeaae605cc809993 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><font face=3D"arial, sans-serif">I usually have 'Use S= how instance' switched off (aka use 'built-in printer'), so I c= an see (at least in crude form) imported or 'system' datatypes that= don't have show instances/also it's a bit more revealing if I get = exceptions.</font><div><font face=3D"arial, sans-serif"><br></font></div><d= iv><font face=3D"arial, sans-serif">I have a datatype:</font><div><font fac= e=3D"arial, sans-serif"><br></font></div><div><font face=3D"arial, sans-ser= if">>=C2=A0 =C2=A0 data Tree a =3D Empty<br>>=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 | Leaf a<br>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= | Node (Tree a) a (Tree a) =C2=A0<br>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 deriving (Eq, Show, Read)<br></font></div></div><div><font face= =3D"arial, sans-serif"><br></font></div><div><font face=3D"arial, sans-seri= f">For results of expressions that were `Node`s, the built-in printer just = ignored the first field. (`show`/print of those values works fine.)</font><= /div><div><font face=3D"arial, sans-serif"><br></font></div><div><font face= =3D"arial, sans-serif">>=C2=A0 =C2=A0 =C2=A0 =C2=A0 FoldableTree> =C2= =A0myTree <> fdmap toUpper myTree<br>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 = Node 'c' Empty<br></font></div><div><font face=3D"arial, sans-serif= "><br></font></div><div><font face=3D"arial, sans-serif">>=C2=A0 =C2=A0 = =C2=A0 =C2=A0 FoldableTree> print $ myTree <> fdmap toUpper myTree= <br>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 Node (Node Empty 'A' (Node Empt= y 'C' (Leaf 'a'))) 'c' Empty<br><br></font></div><d= iv><font face=3D"arial, sans-serif"><br></font></div><div><font face=3D"ari= al, sans-serif">Most disconcerting until I realised what was going on. (Of = course I don't expect the built-in printer to produce pretty output).</= font></div><div><font face=3D"arial, sans-serif"><br></font></div><div><fon= t face=3D"arial, sans-serif">AntC</font></div></div> --000000000000aeaae605cc809993-- --===============2949879067361515022== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KSHVncy1CdWdz IG1haWxpbmcgbGlzdApIdWdzLUJ1Z3NAaGFza2VsbC5vcmcKaHR0cDovL21haWwuaGFza2VsbC5v cmcvY2dpLWJpbi9tYWlsbWFuL2xpc3RpbmZvL2h1Z3MtYnVncw== --===============2949879067361515022==--