Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As mentioned in the comments, you can't have a function to which you'd pass the arity of the function you want to flip. Parameters are computed at runtime, while you need the value at compile time so that you can determine the correct type.</p> <p>Neither you can make it without passing it the arity somehow. For example <code>a -&gt; b -&gt; c -&gt; d</code> could be viewed as a function of three arguments returning <code>d</code>, or as a function if two arguments returning <code>c -&gt; d</code>.</p> <p>Probably the easiest solution would be to define the functions explicitly, like <code>flip2</code>, <code>flip3</code> etc. I know this isn't what you're looking for, but it's the most practical solution.</p> <p>Another option would be to use Template Haskell. Then, the situation is different, because Template Haskell executes (I'd say "meta-") code at compile time. With TH you can create a function that takes a natural number and produces a TH expression that can be compiled into another module. The meta-function could be defined as </p> <pre><code>{-# LANGUAGE TemplateHaskell #-} module GenFlipTH where import Language.Haskell.TH pull :: Int -&gt; Q Exp pull 0 = varE 'flip pull n | n &lt; 0 = fail "Negative arity" | otherwise = [| fmap $(pull (n - 1)) . flip |] -- Here we use the fact that `(-&gt;) r` is a functor. </code></pre> <p>and used in another module to generate the appropriate expression like</p> <pre><code>{-# LANGUAGE TemplateHaskell #-} import GenFlipTH flip3 :: (a -&gt; b3 -&gt; b2 -&gt; b1 -&gt; b -&gt; c) -&gt; (b3 -&gt; b2 -&gt; b1 -&gt; b -&gt; a -&gt; c) flip3 = $( pull 3 ) </code></pre> <p>This is probably closes to your requirements I can get - you determine the function by a number and get compile-time guarantees that it's created and used correctly.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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