<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>Interesting! What's the reason you redefine the Piano numbers and hide the import of the ones from GHC. TypeLits?</div><div><br></div><div>Tom</div><div><br></div><div><br>El 6 mar 2016, a las 07:11, Daniel Filonik <<a href="mailto:d.filonik@hdr.qut.edu.au">d.filonik@hdr.qut.edu.au</a>> escribió:<br><br></div><blockquote type="cite"><div>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">



<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Hi,</p>
<p><br>
</p>
<p>I have been recently playing around with GADTs, using them to keep track of how many times a functor has been applied. This provides a solution to what seems to be a long standing problem, summarized here:</p>
<p><br>
</p>
<p><a title="Ctrl+Click or tap to follow the link" id="LPlnk383182" href="https://byorgey.wordpress.com/2007/08/16/mapping-over-a-nested-functor/">https://byorgey.wordpress.com/2007/08/16/mapping-over-a-nested-functor/</a></p>
<p><br>
</p>
<p>If the nesting depth is part of the type, it is possible to apply fmap automatically as needed. This allows you to write fairly elegant expressions like:</p>
<p><br>
</p>
<p><span class="pl-k">data</span> <span class="pl-c1">Person</span> <span class="pl-k">
=</span> <span class="pl-c1">Person</span> { name <span class="pl-k">::</span> <span class="pl-c1">
String</span>, age <span class="pl-k">::</span> <span class="pl-c1">Integer</span>, gender
<span class="pl-k">::</span> <span class="pl-c1">String</span>, status <span class="pl-k">
::</span> <span class="pl-c1">String</span> } <span class="pl-k">deriving</span> <span class="pl-c1">
Show</span> <br>
</p>
<p><br>
</p>
<p>let persons <span class="pl-k">=</span> fromList' [<span class="pl-c1">Person</span> {name<span class="pl-k">=</span><span class="pl-s"><span class="pl-pds">"</span>Alice<span class="pl-pds">"</span></span>, age<span class="pl-k">=</span><span class="pl-c1">20</span>,
 gender<span class="pl-k">=</span><span class="pl-s"><span class="pl-pds">"</span>F<span class="pl-pds">"</span></span>, status<span class="pl-k">=</span><span class="pl-s"><span class="pl-pds">"</span>Good<span class="pl-pds">"</span></span>},
<span class="pl-c1">Person</span> {name<span class="pl-k">=</span><span class="pl-s"><span class="pl-pds">"</span>Bob<span class="pl-pds">"</span></span>, age<span class="pl-k">=</span><span class="pl-c1">18</span>, gender<span class="pl-k">=</span><span class="pl-s"><span class="pl-pds">"</span>M<span class="pl-pds">"</span></span>,
 status<span class="pl-k">=</span><span class="pl-s"><span class="pl-pds">"</span>Good<span class="pl-pds">"</span></span>},
<span class="pl-c1">Person</span> {name<span class="pl-k">=</span><span class="pl-s"><span class="pl-pds">"</span>Chuck<span class="pl-pds">"</span></span>, age<span class="pl-k">=</span><span class="pl-c1">16</span>, gender<span class="pl-k">=</span><span class="pl-s"><span class="pl-pds">"</span>M<span class="pl-pds">"</span></span>,
 status<span class="pl-k">=</span><span class="pl-s"><span class="pl-pds">"</span>Bad<span class="pl-pds">"</span></span>}]
<span class="pl-k">::</span> <span class="pl-c1">NList</span> N1 <span class="pl-c1">
Person</span><br>
</p>
<p><br>
</p>
<p>persons `select` age<br>
</p>
<p>-- [20,18,16]</p>
<p><br>
</p>
<p>persons `groupby` gender `select` age</p>
<p>-- [[20],[18,16]]</p>
<p><br>
</p>
<p>persons `groupby` gender `groupby` status `select` age</p>
<p>-- [[[20]],[[18],[16]]]<br>
</p>
<p><br>
</p>
<p>Note that "`select` age" works regardless of nesting depth. You can also append or remove nesting levels:<br>
</p>
<p><br>
</p>
<p></p>
<p>persons `groupby` gender `select` age `produce` (\x -> [0..x])</p>
-- [[[0..20]],[[0..18],[0..16]]]
<p></p>
<p><br>
</p>
<p>persons `groupby` gender `reduce` (sumof age)</p>
<p>-- [20, 34]<br>
</p>
<p><br>
</p>
<p>Would this kind of thing be of interest? The code is here:</p>
<p><br>
</p>
<p><a title="Ctrl+Click or tap to follow the link" id="LPlnk826216" href="https://github.com/filonik/nlists">https://github.com/filonik/nlists</a></p>
<p><br>
</p>
<p>Please feel free to suggest improvements.</p>
<p><br>
</p>
<p>Cheers,</p>
<p>Daniel<br>
</p>
</div>


</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Haskell-Cafe mailing list</span><br><span><a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a></span><br><span><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a></span><br></div></blockquote></body></html>