K
K
kornietsbk2020-07-08 21:27:49
Haskell
kornietsbk, 2020-07-08 21:27:49

Why does an error occur when using composition?

I made two functions like this:

prod:: [Integer] -> Integer
prod [] = 1
prod (num:list) = num * prod list

select:: [Integer] -> Integer -> ( Integer -> Integer -> Bool ) -> [Integer]
select list num oper = [x | x <- list, (oper) num x]

And when I want to change prod . select [1..10] 5 (>) or
let fun = select [1..10] 5
prod . fun (>)

It throws this error:
error:
    • Couldn't match expected type ‘a -> [Integer]’
                  with actual type ‘[Integer]’
    • Possible cause: ‘fun’ is applied to too many arguments
      In the second argument of ‘(.)’, namely ‘fun (>)’
      In the expression: prod . fun (>)
      In an equation for ‘it’: it = prod . fun (>)
    • Relevant bindings include
        it :: a -> Integer (bound at <interactive>:156:1)


What's wrong ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mlyamasov, 2020-07-08
@kornietsbk

Because the application of the function has a higher priority.
You need to take the composition in brackets: (prod . fun) (>).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question