2016-09-17 36 views
1

這是我的計劃:複合函數有多個參數

boolToInt True = 1 
boolToInt False = 0 

gt :: Int -> Int -> Int 
gt x y = boolToInt $ (>) x y 

我嘗試重構gtgt = boolToInt . (>),但得到的錯誤:

‘(>)’ is applied to too few arguments

來找我唯一的想法是curryuncurry,但我想這可能會使gtgt x y = boolToInt $ (>) x y更加複雜。

我有更漂亮的功能解決方案,這種組成?

+0

見http://stackoverflow.com/q/20279306/246886 –

+0

可以uncurry '(>)',然後重新結果。 'gt = curry(boolToInt。(uncurry(>)))'。 – chepner

回答

0

你可以這樣做:

(boolToInt .) . (>) 
2

神奇pointfree.io想出了以下解決方案:

gt :: Int -> Int -> Int 
gt = (boolToInt .) . (>) 
+0

哇,http://pointfree.io很酷 – Wentao