Question

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
Was it helpful?

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 (>>).

OTHER TIPS

Without defining a new combinator operator:

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

>> (<<) is a nice trick, and can also be extended for more arguments:

let compose3 f g = f >> (<<) ((<<) g)
val compose3 : ('a -> 'b -> 'c -> 'd) -> ('d -> 'e) -> ('a -> 'b -> 'c -> 'e)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top