Parentheses change code execution

50 Views Asked by At

I'm trying to attempt an Aff computation. Consider the following code:

result <-
    pool # withPool \connection -> do
        execute_ ("insert into user (email, password) values ('"
            <> unwrap userInfo.email <> "', '" <> unwrap userInfo.password <> "')")
            connection
    # attempt

The resulting Aff of attempt is later run using runAff.

Despite using attempt, the error in withPool is propagated to the error handler of runAff.

However, if parentheses are added around the Aff being attempted, the error is "caught" as expected:

result <-
    (pool # withPool \connection -> do
        execute_ ("insert into user (email, password) values ('"
            <> unwrap userInfo.email <> "', '" <> unwrap userInfo.password <> "')")
            connection)
    # attempt

What am I missing here and why is the behavior of these two code snippets different?

1

There are 1 best solutions below

0
On BEST ANSWER

The first snippet is equivalent to

result <-
  pool # withPool (\connection -> do
    execute_ ...
    # attempt)

and not

result <-
  pool # (withPool \connection -> do
            execute_ ...)
       # attempt