{-  
    COMS 4995: Parallel Functional Programming, Fall 2025
    Quiz 6: Parallel evaluation

    1. Close all devices (phone/laptop, etc). Make sure you have an index card to write on, and a pen/pencil.

    2. PLEASE WRITE YOUR NAME AND UNI AS LEGIBLY AS POSSIBLE

    3. Read the quiz question below, and write your answer on your index card. CIRCLE YOUR ANSWER.

    4. Turn in your card at the table in the front of the room.
-}

-- Placeholders for compilation, ignore
import Control.Parallel.Strategies
computeFoo :: Int
computeBar :: Int
computeBaz :: Int
main :: IO ()
(computeFoo, computeBar, computeBaz) = (5, 6, 7)
main = print $ runEval $ parThing rpar rpar rpar

-- Consider the following function:
parThing :: Strategy Int -> Strategy Int -> Strategy Int -> Eval (Int, Int, Int)
parThing s1 s2 s3 = do
    foo <- s1 computeFoo
    bar <- s2 computeBar
    baz <- s3 computeBaz
    return (foo, bar, baz)

{- QUESTION:
Assume that evaluating any of computeFoo, computeBar, or computeBaz to weak-head normal form (WHNF) requires substantial work.
Which of the following invocations CANNOT perform substantial work in parallel?

a) `parThing rseq rseq rpar`
b) `parThing rpar rseq rseq`
c) `parThing rseq rpar rseq`

Please answer with `a`, `b`, or `c`. Assume the program is compiled with -threaded and -rtsopts, and run with +RTS -N3
-}

-- ANSWER: a

-- EXPLANATION:
-- In `parThing rseq rseq rpar`, foo and bar must both be computed sequentially BEFORE the call to `rpar computeBaz`,
-- meanining none of the three computations can happen in parallel; by the time we get to `rpar computeBaz`,
-- foo and bar are already done.