tag:blogger.com,1999:blog-32241238.post1718163728178465368..comments2023-03-25T05:46:26.256-04:00Comments on Why not?: Partial Application in Haskell and ScalaDanhttp://www.blogger.com/profile/06099373265709774874noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-32241238.post-31940991364974797662008-10-14T10:24:00.000-04:002008-10-14T10:24:00.000-04:00_ in Scala is used to convert method to function v..._ in Scala is used to convert method to function value, not function to function value.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-32241238.post-66397106292779458912008-10-14T08:54:00.000-04:002008-10-14T08:54:00.000-04:00It seems a little awkward to distinguish between o...It seems a little awkward to distinguish between operators and functions in haskell; all operators are functions, its just the difference between infix and prefix notation. Notice that the programmer can turn any infix operator into prefix notation by adding parens: <BR/><BR/>(+) 2 3 => 5<BR/><BR/>The programmer can define his own operators as well, again by including the parens:<BR/><BR/>(*+) x y = x * y + x + y<BR/>2 *+ 3 => 11<BR/><BR/>Haskell even lets prefix functions be called using infix notation, using the backtick character:<BR/><BR/>sumSquares x y = x^2 + y^2<BR/>2 `sumSquares` 3 => 13<BR/><BR/>The scala underscore placeholder seems pretty neat, especially for making partial application clearer. In haskell, the most succinct way I know to bind the middle param from your example would be to write:<BR/><BR/>simple x y z = x * (y + z)<BR/>fancy = flip simple 3<BR/>fancy 2 7 => 20<BR/><BR/>But binding the last param seems even trickier. Without resorting to lambdas, the best I've got for now is:<BR/><BR/>fanciest = curry $ (flip $ uncurry simple) 10<BR/>fanciest 3 2 => 36<BR/><BR/>But, the lambda version doesn't hurt my brain trying to read it:<BR/>fanciest = \x y -> simple x y 10Anonymousnoreply@blogger.com