Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>show</code>/<code>read</code> approach will work fine, I use it as well, but only for small values. On larger, more complex values <code>read</code> will be very slow.</p> <p>This contrived example demonstrates the bad performance of <code>read</code>:</p> <pre><code>data RevList a = (RevList a) :&lt; a | Nil deriving (Show, Read) ghci&gt; read "(((((((((((((((Nil)))))))))))))))" :: RevList Int </code></pre> <p>Also, <code>read</code> won't be able to read some valid Haskell expressions, especially ones that use infix constructors (like the <code>:&lt;</code> in my example). The reason for this is that <code>read</code> is unaware of the fixity of operators. This is also why <code>show $ Nil :&lt; 1 :&lt; 2 :&lt; 3</code> will generate a lot of seemingly redundant parentheses. </p> <p>If you want to have serialization for bigger values, I'd suggest to use some other library like <a href="http://code.haskell.org/binary/" rel="noreferrer">Data.Binary</a>. This will be somewhat more complex than a simple <code>show</code>, mainly because of the lack of <code>deriving Binary</code>. However, there are various generic programming solutions to give you <code>deriving</code>-like surrogates.</p> <p><strong>Conclusion:</strong> I'd say, use the <code>show</code>/<code>read</code> solution until you reach its limits (probably once you start building actual applications), then start looking at something more scalable (but also more complex) like Data.Binary.</p> <hr> <p>Side note: To those interested in parsers and more advanced Haskell stuff; The examples I gave came from the paper: <a href="http://www.cs.uu.nl/wiki/pub/Center/TTTAS/paper-read.pdf" rel="noreferrer">Haskel Do You Read Me?</a>, on an alternative, <em>fast</em> <code>read</code>-like function.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload