我正在尝试移植以下Haskell代码(http://codepad.org/MMydRCxo)

foo :: Int -> Int -> Int -> Maybe Bool
foo a b c = if a == 1 then Just True else Nothing

bar :: Int -> Int -> Bool
bar b c = maybe False id $ foo 1 b c

-- point free
bar' :: Int -> Int -> Bool
bar' = ((maybe False id $) .) . foo 1

main = do
  print $ bar 2 3
  print $ bar' 2 3

到榆树,但还没有运气。 (http://share-elm.com/sprout/5271f160e4b03cf6e675bc97)
foo : Int -> Int -> Int -> Maybe Bool
foo a b c = if a == 1 then Just True else Nothing

bar : Int -> Int -> Bool
bar b c = maybe False id <| foo 1 b c

-- point free
bar' : Int -> Int -> Bool
bar' = ((maybe False id <|) .) . foo 1

main = flow down [
    asText <| bar 2 3
  , asText <| bar' 2 3]

有没有想法可以使Elm中的这项工作变得免费? :)

多比

最佳答案

您可以尝试摆脱<|并改为使用前缀表示形式的composition函数。
首先将创建一个带有参数的函数,并使该函数组成foo 1

这样,调用bar' 2将返回采用最后一个参数的组合函数。
IE。 (http://share-elm.com/sprout/52720bc5e4b03cf6e675bcc8):

foo : Int -> Int -> Int -> Maybe Bool
foo a b c = if a == 1 then Just True else Nothing

bar : Int -> Int -> Bool
bar b c = maybe False id <| foo 1 b c

bar' : Int -> Int -> Bool
bar' = (.) (maybe False id) . foo 1
-- the explicit evaluation precedence being: ((.) (maybe False id)) . (foo 1)

main = flow down [
    asText <| bar 2 3
  , asText <| bar' 2 3]

10-08 09:42