9
我正在學習haskell,並且有點困惑,函數應用操作符$ curry的方式如何。
根據GHC的$類型是
*Main>:t ($)
($) :: (a->b) -> a -> b
但我可以鍵入下面的代碼
*Main>map ($ 2) [(*2), (+2), (/2)]
[4.0,4.0,1.0]
據$簽名雖然我認爲我會需要使用翻轉函數,因爲$的第一個參數是(a-> b)。
舉例來說,我不能做以下
curry_test :: Integer -> String -> String
curry_test x y = (show x) ++ " " ++ y
*Main> let x = curry_test "123"
Couldn't match expected type `Integer' with actual type `[Char]'
In the first argument of `curry_test', namely `"123"'
In the expression: curry_test "123"
In an equation for `x': x = curry_test "123"
但我可以做
let x = curry_test 2
提示:'(*)::民一=> A - > A - >了' – DiegoNolan