Hi Haskell Cafe,<br><br>I&#39;m finding that I really like type families.&nbsp; For instance, the GHC.List.lookup and Data.Map.lookup functions annoy me because their names clash, yet their type are so similar.&nbsp; With type families, I could define a more generic lookup function like this:<br>
<br>import Data.Map as MAP<br>import GHC.List as LIST<br><br>class MapType ma where<br>&nbsp;&nbsp; type Key ma<br>&nbsp;&nbsp; type Item ma<br>&nbsp;&nbsp; lookup :: Key ma -&gt; ma -&gt; Maybe (Item ma)<br><br>instance (Ord ka) =&gt; MapType (MAP.Map ka a) where<br>
&nbsp;&nbsp; type Key (MAP.Map ka a) = ka<br>&nbsp;&nbsp; type Item (MAP.Map ka a) = a<br>&nbsp;&nbsp; lookup ka ma = MAP.lookup ka ma<br><br>instance (Eq ka) =&gt; MapType [(ka, a)] where<br>&nbsp;&nbsp; type Key [(ka, a)] = ka<br>&nbsp;&nbsp; type Item [(ka, a)] = a<br>
&nbsp;&nbsp; lookup ka ma = LIST.lookup ka ma<br><br>This lookup function works on both &quot;Map ka a&quot; and &quot;[(ka, a)]&quot; types and I no longer need to qualify my lookup function with the module name.<br><br>The downside I suppose is that lookup is no longer a function that can be manipulated freely:<br>
<br>*Main&gt; let x = lookup<br>*Main&gt; let y = Fx.Data.Map.lookup<br><br>&lt;interactive&gt;:1:8:<br>&nbsp;&nbsp;&nbsp; Ambiguous type variable `ma&#39; in the constraint:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `Fx.Data.Map.MapType ma&#39;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arising from a use of `Fx.Data.Map.lookup&#39; at &lt;interactive&gt;:1:8-25<br>
&nbsp;&nbsp;&nbsp; Probable fix: add a type signature that fixes these type variable(s)<br><br>A shame that.&nbsp; I had been hoping it would be possible to have a generic lookup function that could be used in every way the current collection of various lookup functions can be used.<br>
<br>So much nicer if &#39;y&#39; above could be bound to the Fx.Data.Map.lookup with the same type:<br><br>*Main&gt; :t Fx.Data.Map.lookup<br>Fx.Data.Map.lookup :: forall ma.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (Fx.Data.Map.MapType ma) =&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Fx.Data.Map.Key ma -&gt; ma -&gt; Maybe (Fx.Data.Map.Item ma)<br><br>And then have the ambiguity resolve later when &#39;y&#39; is actually used.<br><br>-John<br><br>