Aron W.
Aron W.

Reputation: 1

What variable will be chosen if I use anonymous functions?

  findSatisfying :: (Int -> Bool) -> Int -> Int -> Bool
  findSatisfying p from to =
  divideAndConquer
  (\(x,y) -> x >= y)

  (\(x,y) -> x==y && p x)

  (\(x,y) -> ((x,x+((y-x) `div` 2)) , ((x+(y-x) `div` 2)+1,y))) 

  (||)

  (from, to)

This is a function to find an Interger in a List which satifies the function p which is in the form(Int->Bool).

Furthermore its using anonymous functions with (x,y) -> ... which correspond to "from" and "to".

I am not sure why they correspond to "from" and "to" however and not to "p".

Thanks in advance.

Upvotes: 0

Views: 65

Answers (1)

sepp2k
sepp2k

Reputation: 370435

The parameters of an anonymous function, just like the parameters of named a function, will take whichever values the function is applied to. So if the parameters of your anonymous functions take on the values from and to, it's because divideAndConquer applies them to those values.

Upvotes: 3

Related Questions