Reputation: 3762
I have a composition of functions, many of them operators, to raise a constant to the power of a constant minus the size of the ith set in a list. Here's my code:
(k^).(n-).size.(phi !!) i
When I tried it on a test case I got
<interactive>:64:16-25:
Couldn't match expected type ‘a -> Set a0’
with actual type ‘Set a1’
Relevant bindings include
it :: a -> c (bound at <interactive>:64:1)
Possible cause: ‘phi !!’ is applied to too many arguments
In the second argument of ‘(.)’, namely ‘(phi !!) 3’
In the second argument of ‘(.)’, namely ‘size . (phi !!) 3’
However,
(k^)$(n-)$size$(phi !!)$i
works. What's wrong? Why does composition not work but application work? Also, is composing the operators in parentheses the most idiomatic way to do it? It feels weird.
Upvotes: 1
Views: 1977
Reputation: 67507
Note that you can use parenthesis to group function compositions,
((k^).(n-).size.(phi !!)) i
should work.
Upvotes: 1
Reputation: 92067
Rather than f . g . h x
, you want f . g . h $ x
: the former calls h x
immediately and then composes that, as a function, with f
and g
The latter composes together f
, g
, and h
into a new function and then calls that on i
.
Upvotes: 3