Search code examples
f#function-composition

Tupled function composition


I'm curious why this

let f = (fun a b -> a, b) >> obj.Equals

gives the error

No accessible member or object constructor named 'Equals' takes 1 arguments

but this works

let f = (fun a -> a, a) >> obj.Equals

Solution

  • Consider the types. (>>) has type ('a -> 'b) ->('b -> 'c) -> ('a -> 'c), but you're trying to call it with arguments of type 'a -> ('b -> 'a*'b) and obj * obj -> bool, which can't be made to fit together like that.

    You could of course define a new combinator for composing binary and unary functions:

    let ( >>* ) f g a b = f a b |> g
    

    in which case you can use it in your example instead of (>>).