Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Paul's and yairchu's are both good explanations.</p> <p>I'd like to add that the function being lifted can have an arbitrary number of arguments and that they don't have to be of the same type. For example, you could also define a liftFoo1:</p> <pre><code>liftFoo1 :: (a -&gt; b) -&gt; Foo a -&gt; Foo b </code></pre> <p>In general, the lifting of functions that take 1 argument is captured in the type class <code>Functor</code>, and the lifting operation is called <code>fmap</code>:</p> <pre><code>fmap :: Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b </code></pre> <p>Note the similarity with <code>liftFoo1</code>'s type. In fact, if you have <code>liftFoo1</code>, you can make <code>Foo</code> an instance of <code>Functor</code>:</p> <pre><code>instance Functor Foo where fmap = liftFoo1 </code></pre> <p>Furthermore, the generalization of lifting to an arbitrary number of arguments is called <em>applicative style</em>. Don't bother diving into this until you grasp the lifting of functions with a fixed number of arguments. But when you do, <a href="http://learnyouahaskell.com/functors-applicative-functors-and-monoids" rel="noreferrer">Learn you a Haskell</a> has a good chapter on this. The <a href="http://www.haskell.org/haskellwiki/Typeclassopedia" rel="noreferrer">Typeclassopedia</a> is another good document that describes <em>Functor</em> and <em>Applicative</em> (as well as other type classes; scroll down to the right chapter in that document).</p> <p>Hope this helps!</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