× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS
Carsten König
Jul 17, 2015
<p>The problem here is that <code>intersect</code> <em>takes 2 arguments</em> (in a sense) </p> <p>you can provide one of the arguments explicitly:</p> <pre><code>&gt; let f a = length . nub . intersect a &gt; :t f f :: Eq a =&gt; [a] -&gt; [a] -&gt; Int </code></pre> <p>or you can use a fun little operator like <code>(.:) = (.) . (.)</code>:</p> <pre><code>&gt; let (.:) = (.) . (.) &gt; :t length .: (nub .: intersect) length .: (nub .: intersect) :: Eq a =&gt; [a] -&gt; [a] -&gt; Int </code></pre> <p>here is a version where you don't need the parens:</p> <p>import Data.List</p> <pre><code>infixr 9 .: (.:) :: (c -&gt; d) -&gt; (a -&gt; b -&gt; c) -&gt; a -&gt; b -&gt; d (.:) = (.).(.) f :: Eq a =&gt; [a] -&gt; [a] -&gt; Int f = length .: nub .: intersect </code></pre> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/25738171/How%20to%20use%20(.)%20in%20Haskell/25738273">Stack Overflow</a>.</p>
comments powered by Disqus