Mia.M
Mia.M

Reputation: 97

The order of functions' execution in a high order function

I have a function here

(map (\ (a, b) -> dir a b) $ routes 

where routes is a list of tuples and it contains

routes = [...
           ("graph-fb", seeOther redirectUrlGraphEmail $ toResponse ""),
           ("post-fb", seeOther redirectUrlGraphPost $ toResponse ""),
          ...]

Here is the question: when I call this function to apply dir on each tuple, which function is going to be returned as b in dir a b first, the function seeOther redirectUrlGraphEmail or seeOther redirectUrlGraphEmail $ toResponse ""?

Upvotes: 0

Views: 115

Answers (2)

dfeuer
dfeuer

Reputation: 48581

There's no way to tell from that code. Even ignoring the compiler's freedom to reorganize your program in various dramatic ways, the usual approach to Haskell evaluation is lazy, which you can think of as demand-driven, case-driven, and (ultimately) I/O-driven. Whoever actually inspects the results determines the evaluation order.

Upvotes: 0

Chad Gilbert
Chad Gilbert

Reputation: 36375

Tuples items are separated by , which means that in your example for graph-fb,

a == "graph-fb"
b == seeOther redirectUrlGraphEmail $ toResponse ""

The first function call to resolve will be toResponse "", and that will be fed into seeOther as the second parameter. The result of this will then have the label b inside the mapping function.

Upvotes: 2

Related Questions