The issue is that the Haskell&#39;s Text type only supports conversions from PostgreSQL&#39;s text, char, varchar,  and a few other types.   So this is why converting to Text first doesn&#39;t work.<div><br></div><div>What you really want to do is something like the code that follows.   I&#39;ll admit that your code is shorter and cleaner;  perhaps there is a sensible way to change the FromField interface to make it (or something like it) work.   I&#39;m certainly not satisfied with the FromField/FromRow interface yet,  but I haven&#39;t really worked on ways to improve it further.   It&#39;d be nice to develop a corpus of use cases that we want to cover.</div>
<div><br></div><div>Best,</div><div>Leon</div><div><br></div><div><br></div><div><div>data X = X Float</div><div>       | Y Float</div><div><br></div><div>buildX :: B.ByteString -&gt; OK (Float -&gt; X)</div><div>buildX &quot;x&quot;      = pure X</div>
<div>buildX &quot;y&quot;      = pure Y</div><div>buildX val      = returnError ConversionFailed (ellipsis val)</div><div><br></div><div>ellipsis :: B.ByteString -&gt; String</div><div>ellipsis x | B.length x &gt; 25 = take 20 (B.unpack x) ++ &quot;[...]&quot;</div>
<div>           | otherwise       = B.unpack x</div><div><br></div><div>instance FromField (Float -&gt; X) where</div><div>    fromField f mv | typename f == &quot;x&quot;  =  case mv of </div><div>                                             Nothing -&gt; returnError UnexpectedNull &quot;some possibly more informative messgage&quot;</div>
<div>                                             Just v  -&gt; buildX v</div><div>                   | otherwise          =  returnError TypesIncompatible &quot;some possibly more informative message&quot;</div><div><br>
</div><div>instance FromRow X where</div><div>    fromRow = field &lt;*&gt; (field :: RowParser Float)</div><div><br></div><div><br></div><div class="gmail_quote">On Sat, Jun 16, 2012 at 3:02 PM, Luke Hoersten <span dir="ltr">&lt;<a href="mailto:luke@hoersten.org" target="_blank">luke@hoersten.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><pre style="text-align:left;font-size:13px;margin-bottom:0px;margin-top:0px"><span><font face="arial, helvetica, sans-serif">I&#39;m trying to use postgresql enum types to represent Haskell types like in the code snippet below but an receiving the following error:</font></span></pre>


<pre style="text-align:left;font-size:13px;margin-bottom:0px;margin-top:0px"><span><pre style="text-align:-webkit-auto;white-space:pre-wrap;word-wrap:break-word">&quot;Incompatible {errSQLType = &quot;x&quot;, errHaskellType = &quot;Text&quot;, errMessage = &quot;types incompatible&quot;}&quot;</pre>
<pre style="text-align:-webkit-auto;white-space:pre-wrap;word-wrap:break-word"><font face="arial, helvetica, sans-serif">In other areas of my code (not shown) I&#39;m successfully using Text to convert to and from Postgersql enum types but it doesn&#39;t seem to work in the case below. Any ideas what I&#39;m doing wrong?</font></pre>


<pre style="text-align:-webkit-auto;white-space:pre-wrap;word-wrap:break-word"><font face="arial, helvetica, sans-serif">Thanks, Luke</font></pre><pre style="text-align:-webkit-auto;white-space:pre-wrap;word-wrap:break-word">
<br></pre></span></pre><pre style="text-align:left;font-size:13px;margin-bottom:0px;margin-top:0px"><span style="color:rgb(57,116,96)"><br></span></pre><pre style="text-align:left;font-size:13px;margin-bottom:0px;margin-top:0px">
<span style="color:rgb(57,116,96)"><br></span></pre><pre style="text-align:left;font-size:13px;margin-bottom:0px;margin-top:0px"><span style="color:rgb(57,116,96)">import</span>           <span style="color:rgb(79,67,113)">Database</span><span style="color:rgb(51,51,51)">.</span><span style="color:rgb(79,67,113)">PostgreSQL</span><span style="color:rgb(51,51,51)">.</span><span style="color:rgb(79,67,113)">Simple</span><span style="color:rgb(51,51,51)">.</span><span style="color:rgb(79,67,113)">FromField</span>        <span>(</span><span style="color:rgb(79,67,113)">FromField</span><span>,</span> <span style="color:rgb(51,51,51)">fromField</span><span>)</span>
<span style="color:rgb(57,116,96)">import</span>           <span style="color:rgb(79,67,113)">Database</span><span style="color:rgb(51,51,51)">.</span><span style="color:rgb(79,67,113)">PostgreSQL</span><span style="color:rgb(51,51,51)">.</span><span style="color:rgb(79,67,113)">Simple</span><span style="color:rgb(51,51,51)">.</span><span style="color:rgb(79,67,113)">FromRow</span>          <span>(</span><span style="color:rgb(79,67,113)">FromRow</span><span>,</span> <span style="color:rgb(51,51,51)">field</span><span>,</span> <span style="color:rgb(51,51,51)">fromRow</span><span>)</span>
<span style="color:rgb(57,116,96)">import</span>           <span style="color:rgb(79,67,113)">Database</span><span style="color:rgb(51,51,51)">.</span><span style="color:rgb(79,67,113)">PostgreSQL</span><span style="color:rgb(51,51,51)">.</span><span style="color:rgb(79,67,113)">Simple</span><span style="color:rgb(51,51,51)">.</span><span style="color:rgb(79,67,113)">SqlQQ</span>            <span>(</span><span style="color:rgb(51,51,51)">sql</span><span>)</span>


<span style="color:rgb(57,116,96)">data</span> <span style="color:rgb(79,67,113)">X</span> <span>=</span> <span style="color:rgb(79,67,113)">X</span> <span style="color:rgb(79,67,113)">Float</span>
       <span>|</span> <span style="color:rgb(79,67,113)">Y</span> <span style="color:rgb(79,67,113)">Float</span>


<span>buildX</span> <span>::</span> <span style="color:rgb(79,67,113)">Text</span> <span>-&gt;</span> <span style="color:rgb(79,67,113)">Float</span> <span>-&gt;</span> <span style="color:rgb(79,67,113)">X</span>
<span>buildX</span> <span style="color:rgb(54,99,84)">&quot;x&quot;</span>      <span>=</span> <span style="color:rgb(79,67,113)">X</span>
<span>buildX</span> <span style="color:rgb(54,99,84)">&quot;y&quot;</span>      <span>=</span> <span style="color:rgb(79,67,113)">Y</span>


<span style="color:rgb(57,116,96)">instance</span> <span style="color:rgb(79,67,113)">FromField</span> <span>(</span><span style="color:rgb(79,67,113)">Float</span> <span>-&gt;</span> <span style="color:rgb(79,67,113)">X</span><span>)</span> <span style="color:rgb(57,116,96)">where</span>
    <span style="color:rgb(51,51,51)">fromField</span> <span style="color:rgb(51,51,51)">f</span> <span style="color:rgb(51,51,51)">v</span> <span>=</span> <span style="color:rgb(51,51,51)">buildX</span> <span style="color:rgb(51,51,51)">&lt;$&gt;</span> <span style="color:rgb(51,51,51)">fromField</span> <span style="color:rgb(51,51,51)">f</span> <span style="color:rgb(51,51,51)">v</span>


<span style="color:rgb(57,116,96)">instance</span> <span style="color:rgb(79,67,113)">FromRow</span> <span style="color:rgb(79,67,113)">X</span> <span style="color:rgb(57,116,96)">where</span>
    <span style="color:rgb(51,51,51)">fromRow</span> <span>=</span> <span style="color:rgb(51,51,51)">field</span> <span style="color:rgb(51,51,51)">&lt;*&gt;</span> (field :: RowParser Float)</pre>

<pre style="text-align:left;font-size:13px;margin-bottom:0px;margin-top:0px"><br></pre><pre style="text-align:left;font-size:13px;margin-bottom:0px;margin-top:0px"><br></pre>
<br>_______________________________________________<br>
database-devel mailing list<br>
<a href="mailto:database-devel@haskell.org">database-devel@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/database-devel" target="_blank">http://www.haskell.org/mailman/listinfo/database-devel</a><br>
<br></blockquote></div><br></div>