Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This isn't possible with just Haskell's record system. What you want are <em>lenses</em>; this <a href="https://stackoverflow.com/questions/5767129/lenses-fclabels-data-accessor-which-library-for-structure-access-and-mutatio">previous Stack Overflow question</a> and its top answer are a good introduction. Personally, I use the <a href="http://hackage.haskell.org/package/data-lens" rel="nofollow noreferrer">data-lens</a> package talked about there. (See also <a href="http://hackage.haskell.org/package/data-lens-fd" rel="nofollow noreferrer">data-lens-fd</a> to use it with the <a href="http://hackage.haskell.org/packages/archive/mtl/latest/doc/html/Control-Monad-State-Class.html#t:MonadState" rel="nofollow noreferrer">MonadState</a> class from mtl — if you don't know what that is, just know that you should probably use it whenever you want to use lenses in a <code>State</code> monad.)</p> <p>The <a href="http://hackage.haskell.org/package/data-lens-template" rel="nofollow noreferrer">data-lens-template</a> package might be the application of Template Haskell you want; it derives lens definitions for record fields.</p> <p>The other popular lens package is <a href="http://hackage.haskell.org/package/fclabels" rel="nofollow noreferrer">fclabels</a>. I prefer data-lens for its simplicity and speed; fclabels (as of version 1.0) is slightly more flexible, but you don't need that flexibility for what you want to do. (Note that due to its newly-increased flexibility, fclabels' <code>(:-&gt;)</code> type can no longer be directly translated to the simple definition of lenses, as mentioned in the Stack Overflow answer I linked.)</p>
 

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