Q:

Haskell - Custom functor instance on data type with function constructor

I am having trouble writing my own instance of functor for a custom data type (that I cannot change). The data types are defined as:
data Foo a = Baz String (Qux -> Foo a) | Bar a
data Qux = None | Quux String

My problem is with writing a functor for the Foo type. Specifically, I'm not sure how to properly apply my functor function f to the function in the Foo. I was thinking of somehow calling the function in the constructor, but since I don't have any Qux's available for use, I'm stuck.
instance Functor Foo where
    fmap f (Bar a) = Bar (f a)
    fmap f (Baz s ???) = Baz s (???) -- What goes here?

    -- Clearly, something like this doesn't work
    -- fmap f (Baz s g) = Baz s (f g) 

    -- I've also tried something like this, but I'm not sure where to go from there
    -- fmap f (Baz s (None   -> Bar b)) = Baz s (f b) ???
    -- fmap f (Baz s (Quux x -> Bar b)) = Baz s ???

A:

Let's start by completing the left side of this equation. We can write g to bind your function to a variable.
fmap f (Baz s g) = Baz s (???)
Then, we need to fill in the question marks with another function, that takes a Qux and returns a Foo b.
fmap f (Baz s g) = Baz s (\q -> ???)
We can only do one thing with q, which is apply g to it.
fmap f (Baz s g) = Baz s (\q -> g q)
However, this gives us a Foo a, but we need a Foo b! We don't have a function to do that. We do, however, have f, which takes an a and returns a b. If only there were a way to take a -> b and turn it into Foo a -> Foo b... oh wait, there is, it's called fmap!
fmap f (Baz s g) = Baz s (\q -> fmap f (g q))
If you want to write the function in point free notation (https://wiki.haskell.org/Pointfree), you can do this instead.
fmap f (Baz s g) = Baz s (fmap f . g)

A:

Follow the types:
fmap f (Baz s g) = GOAL
   -- f    :: a -> b
   -- s    :: String
   -- g    :: Qux -> Foo a
   -- GOAL :: Foo b

So we're looking for a Foo b (the GOAL line).  We can make one with either Bar or Baz.  fmap should preserve the structure so it ought to be Baz.  The String argument to Baz probably should not change, it's only the second argument that poses the problem.
fmap f (Baz s g) = Baz s GOAL
   -- f    :: a -> b
   -- s    :: String
   -- g    :: Qux -> Foo a
   -- GOAL :: Qux -> Foo b

Now we have to make a Qux -> Foo b.  If you need to make a function, lambda is the essential tool (there are others, but lambda is the granddaddy).  So make a lambda:
fmap f (Baz s g) = Baz s (\x -> GOAL)
   -- f    :: a -> b
   -- s    :: String
   -- g    :: Qux -> Foo a
   -- x    :: Qux          <-- NEW
   -- GOAL :: Foo b

Notice that we now have an x :: Qux to work with.  Using g and x we can make a Foo a, and then using fmap f recursively1 we can make the required Foo b.
Notice how I'm just filling out the expression one tiny step at a time, replacing unknown arguments with goals, then taking a step back to consider what variables I have in scope and what their types are.  Continue doing this until a path to the goal is clear.

1 A recursive type will usually have a corresponding recursive fmap definition.  The place the recursion happens in fmap corresponds exactly to the way the type is recursive.

