Hello,<br>I just noticed that the instances for this example look more readable when written with two recently proposed Haskell extensions. Perhaps we should consider implementing these in GHC?<br><div><br></div><div>Using chain instances: (<meta http-equiv="content-type" content="text/html; charset=utf-8"><a href="http://web.cecs.pdx.edu/~mpj/pubs/instancechains.pdf">http://web.cecs.pdx.edu/~mpj/pubs/instancechains.pdf</a>)<br>
<br><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">&gt; instance DeepFlat a b =&gt; DeepFlat [a] b where dflat = concatMap dflat<br>&gt;    else                  DeepFlat a   a where dflat = id<br>
&gt;    else fails    <br></font><br></div><div>And with the fun. deps. in functional notation: (<a href="http://web.cecs.pdx.edu/~mpj/pubs/fundeps-design.pdf">http://web.cecs.pdx.edu/~mpj/pubs/fundeps-design.pdf</a>)</div>
<div><div><br><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">&gt; instance DeepFlat [a] (DeepFlat a) where dflat = concatMap dflat<br>&gt;     else DeepFlat a   a            where dflat = id<br>
&gt;     else fails<br></font><br></div><div>Happy new year!<br>-Iavor<br><br><br><br><br><br>On Thu, Dec 30, 2010 at 3:52 AM,  &lt;<a href="mailto:oleg@okmij.org">oleg@okmij.org</a>&gt; wrote:<br>&gt;<br>&gt; William Murphy wrote:<br>
&gt;&gt; I&#39;ve spent a lot of time trying to write a version of concat, which<br>&gt;&gt; concatenates lists of any &quot;depth&quot;:<br>&gt;<br>&gt; It is a little bit more involved, but quite possible. The code is not<br>
&gt; much longer than the one you wrote (essentially, three lines: one<br>&gt; class and two instance declarations). Here is the complete code:<br>&gt;<br>&gt;<br>&gt; {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}<br>
&gt; {-# LANGUAGE TypeFamilies, FlexibleInstances #-}<br>&gt; {-# LANGUAGE UndecidableInstances #-}<br>&gt; {-# LANGUAGE OverlappingInstances #-}<br>&gt;<br>&gt; module DeepFlat where<br>&gt;<br>&gt;<br>&gt; class DeepFlat a b | a -&gt; b where<br>
&gt;    dflat :: [a] -&gt; [b]<br>&gt;<br>&gt; -- If we flatten a list of lists<br>&gt; instance DeepFlat a b =&gt; DeepFlat [a] b where<br>&gt;    dflat = concatMap dflat<br>&gt;<br>&gt; -- If we are given a list of non-lists<br>
&gt; instance a ~ b =&gt; DeepFlat a b where<br>&gt;    dflat = id<br>&gt;<br>&gt; test1 = dflat &quot;abracadabra&quot;<br>&gt; -- &quot;abracadabra&quot;<br>&gt;<br>&gt; test2 = dflat [&quot;abra&quot;,&quot;cadabra&quot;]<br>
&gt;<br>&gt; test3 = dflat [[&quot;ab&quot;,&quot;ra&quot;],[&quot;cad&quot;,&quot;abra&quot;]]<br>&gt; test4 = dflat [[[&quot;a&quot;,&quot;b&quot;],[&quot;ra&quot;]],[[&quot;cad&quot;,&quot;abra&quot;]]]<br>&gt;<br>&gt;<br>
&gt;<br>&gt;<br>&gt; _______________________________________________<br>&gt; Haskell-Cafe mailing list<br>&gt; <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
&gt;<br><br></div></div></div>