{-  
    COMS 4995: Parallel Functional Programming, Fall 2025
    Quiz 4: Monads

    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.
-}

-- Consider the following function:
mysequence :: [Maybe Int] -> Maybe [Int]
mysequence []     = return []
mysequence (x:xs) = do
    x'  <- x
    xs' <- mysequence xs
    return $ x' : xs'

-- QUESTION:
-- What is the result of `mysequence [Just 5, Nothing, Just 6]`?

-- CORRECT ANSWER:
-- Nothing

-- EXPLANATION:
-- This `do` block is in the Maybe monad (which we can tell from the return type, Maybe [Int]).
-- Therefore, in the recursive call to mysequence, when x is Nothing, line 18 will "fail", so the entire
-- chain of computation is Nothing, including subsequent recursive calls.

-- This function is called mysequence because it is equivalent to `sequence` in the Prelude.
-- Or rather, a less general version. sequence has type 
-- sequence :: (Traversable t, Monad m) => t (m a) -> m (t a)