This does not work because gcd requires two inputs, while the composition of functions provides only gcd one input. Consider the definition of the composition of the function:
f . g = \x -> f (gx)
Therefore, the expression (== 1) . gcd (== 1) . gcd equivalent to:
\x -> (== 1) (gcd x)
This is not what you want. Do you want to:
\xy -> (== 1) (gcd xy)
You can define a new operator to create a unary function with a binary function:
f .: g = \xy -> f (gxy)
Then your expression will look like this:
relativelyPrime = (== 1) .: gcd
In fact, the operator (.:) can be defined in terms of composition of functions:
(.:) = (.) . (.)
It looks like an owl, but they are really equivalent. So another way to write an expression:
relativelyPrime = ((== 1) .) . gcd
If you want to understand what is going on, take a look: What does (f.) Do. Does g mean in Haskell?
source share