
On p. 76 of RWH, it says: "If a function or constructor takes two or more arguments, we have the option of using it in infix form, where we place it between its first and second arguments." Here is my code: func2 x y = x + y func3 x y z = x + y + z Here are the results: *Main> func2 10 20 30 *Main> 10 `func2` 20 30 *Main> func3 10 20 30 60 *Main> 10 `func3` 20 30 <interactive>:1:11: No instance for (Num (t1 -> t)) arising from the literal `20' at <interactive>:1:11-15 Possible fix: add an instance declaration for (Num (t1 -> t)) In the second argument of `func3', namely `20 30' In the expression: 10 `func3` 20 30 In the definition of `it': it = 10 `func3` 20 30 How do you get a function to work using infix notation when it has 3 arguments?

On 20 Mar 2009, at 12:05, 7stud wrote:
On p. 76 of RWH, it says:
"If a function or constructor takes two or more arguments, we have the option of using it in infix form, where we place it between its first and second arguments."
Here is my code:
func2 x y = x + y
func3 x y z = x + y + z
Here are the results:
*Main> func2 10 20 30 *Main> 10 `func2` 20 30 *Main> func3 10 20 30 60 *Main> 10 `func3` 20 30
<interactive>:1:11: No instance for (Num (t1 -> t)) arising from the literal `20' at <interactive>:1:11-15 Possible fix: add an instance declaration for (Num (t1 -> t)) In the second argument of `func3', namely `20 30' In the expression: 10 `func3` 20 30 In the definition of `it': it = 10 `func3` 20 30
How do you get a function to work using infix notation when it has 3 arguments?
Prelude> (10 `func3` 20) 30 60 Bob

On 2009 Mar 20, at 7:05, 7stud wrote:
func2 x y = x + y
func3 x y z = x + y + z
Here are the results:
*Main> func2 10 20 30 *Main> 10 `func2` 20 30 *Main> func3 10 20 30 60 *Main> 10 `func3` 20 30
<interactive>:1:11: No instance for (Num (t1 -> t)) arising from the literal `20' at <interactive>:1:11-15
Keep in mind that any function taking multiple arguments is indistinguishable from a function taking a single argument and returning a function that takes more arguments. So we have in this case "10 `func3` 20" which requires another argument. But because of Haskell evaluation rules, writing "10 `func3` 20 30" causes Haskell to try to evaluate "20 30" as a function (i.e. Haskell infers "10 `func3` (20 30)". We need to tell Haskell not to do this: (10 `func3` 20) 30 It can easily be seen that "(10 `func3` 20)" returns a function which is applied to "30", as we intended. (hm, I'm starting to sound like Oleg. not necessarily a good thing... this is not a research paper :) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH
participants (3)
-
7stud
-
Brandon S. Allbery KF8NH
-
Thomas Davie