Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a general way to tell the number of parameters of a function in Haskell?
    primarykey
    data
    text
    <p>I can tell the number of parameters of a function with the following code</p> <pre><code>{-#Language MultiParamTypeClasses#-} {-#Language FunctionalDependencies#-} {-#Language UndecidableInstances#-} data Zero data Succ a class Number a instance Number Zero instance (Number a) =&gt; Number (Succ a) class NotFunction a instance NotFunction Int instance NotFunction Float instance NotFunction (IO a) class (Number n) =&gt; FunctionLevel f n | f -&gt; n where functionLevel :: f -&gt; n instance FunctionLevel Int Zero where functionLevel = undefined instance FunctionLevel Float Zero where functionLevel = undefined instance FunctionLevel (IO a) Zero where functionLevel = undefined instance FunctionLevel Double Zero where functionLevel = undefined instance (FunctionLevel f' n) =&gt; FunctionLevel (a-&gt;f') (Succ n) where functionLevel = undefined </code></pre> <p>And we get:</p> <pre><code>*Main&gt; :t functionLevel (undefined::a-&gt;b-&gt;Int) functionLevel (undefined::a-&gt;b-&gt;Int) :: Succ (Succ Zero) *Main&gt; :t functionLevel (undefined::a-&gt;b-&gt;Double) functionLevel (undefined::a-&gt;b-&gt;Double) :: Succ (Succ Zero) *Main&gt; :t functionLevel (undefined::a-&gt;b-&gt;c-&gt;d-&gt;IO a) functionLevel (undefined::a-&gt;b-&gt;c-&gt;d-&gt;IO a) :: Succ (Succ (Succ (Succ Zero))) *Main&gt; :t functionLevel (undefined::a-&gt;b-&gt;c-&gt;d-&gt;Int) functionLevel (undefined::a-&gt;b-&gt;c-&gt;d-&gt;Int) :: Succ (Succ (Succ (Succ Zero))) </code></pre> <p>As you can see, <code>functionLevel</code> performs just as we expected for functions "ended" with some special types. My question is: could we generalize this to tell parameter number of an arbitrary function?</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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