Note that there are some explanatory texts on larger screens.

plurals
  1. POHaskell: composing function with two floating arguments fails
    primarykey
    data
    text
    <p>I am trying to compose a function of type <code>(Floating a) =&gt; a -&gt; a -&gt; a</code> with a function of type <code>(Floating a) =&gt; a -&gt; a</code> to obtain a function of type <code>(Floating a) =&gt; a -&gt; a -&gt; a</code>. I have the following code:</p> <pre><code>test1 :: (Floating a) =&gt; a -&gt; a -&gt; a test1 x y = x test2 :: (Floating a) =&gt; a -&gt; a test2 x = x testBoth :: (Floating a) =&gt; a -&gt; a -&gt; a testBoth = test2 . test1 --testBoth x y = test2 (test1 x y) </code></pre> <p>However, when I compile it in GHCI, I get the following error:</p> <pre><code>/path/test.hs:8:11: Could not deduce (Floating (a -&gt; a)) from the context (Floating a) arising from a use of `test2' at /path/test.hs:8:11-15 Possible fix: add (Floating (a -&gt; a)) to the context of the type signature for `testBoth' or add an instance declaration for (Floating (a -&gt; a)) In the first argument of `(.)', namely `test2' In the expression: test2 . test1 In the definition of `testBoth': testBoth = test2 . test1 Failed, modules loaded: none. </code></pre> <p>Note that the commented-out version of <code>testBoth</code> compiles. The strange thing is that if I remove the <code>(Floating a)</code> constraints from all type signatures or if I change <code>test1</code> to just take <code>x</code> instead of <code>x</code> and <code>y</code>, <code>testBoth</code> compiles.</p> <p>I've searched StackOverflow, Haskell wikis, Google, etc. and not found anything about a restriction on function composition relevant to this particular situation. Does anyone know why this is happening?</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. 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