Point free notation with several functional parameters

I am trying to port the following Haskell code ( 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

to Elma, but so far no luck. ( 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]

Any ideas, if there is an opportunity to make this working point free in Elm? :)

Finish it

+4
source share
2 answers

You can try to get rid of <|and use the composition function in prefix notation instead. First, a function will be created that takes an argument, and that function will constitute foo 1.

, bar' 2 , . (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]
+4

Haskell :

(f .) . g
(.) f . g
(.) ((.) f) g
((.).(.)) f g
(\x y -> f (g x y))

, f , g , 2 g, f. "" , , .

, Elm, :

(.:) = (<<)<<(<<) -- owl operator definition
(<<) f << g
(<<) ((<<) f) g
f .: g

:

((<<) negate << (+)) 3 4 -- returns -7
(negate .: (+)) 3 4      -- returns -7

: Elm 0.13 (.) (<<), (>>) flip (<<)

+2

All Articles