{-  
    COMS 4995: Parallel Functional Programming, Fall 2025
    Quiz 3: Typeclasses

    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 Foo datatype defined below:
data Foo a = Bar    a
           | Baz    (Foo a) a a
           | FooBar (Foo a) a
           deriving Show

instance Functor Foo where -- and Functor instance:
    fmap f (Bar x)        = Bar    (f x)
    fmap f (Baz foo x y)  = Baz    (fmap f foo) (f x) (f y)
    fmap f (FooBar foo x) = FooBar (fmap f foo) (f x)

-- QUESTION:
-- Does this Functor instance for Foo satisfy the Functor laws?
-- fmap id == id
-- (fmap f) . (fmap g) == fmap (f . g)

-- CORRECT ANSWER:
-- "Yes"

-- EXPLANATION:
-- `fmap id` has no effect on a Foo. It only applies `id` to each element recursively.
-- Similarly, `fmap` does not do anything to a Foo beyond applying its argument to the elements, so
-- mapping the composition `f . g` is the same as mapping them in one after the other.