= Solution
Only the first constructor needs to be inspected:
``
headZig :: Zig a b -> a
headZig (Cins x _) = x
headZig Nil = error "headZig: empty input"
headZag :: Zag a b -> a
headZag (Cans x _) = x
headZag Nal = error "headZag: empty input"
``
The first <type parameter> is the type of the first element in either <algebraic data type>. The source examples therefore return \b[`1` and `"C"`], respectively. These functions are partial at empty inputs, as allowed by the stated nonempty-input requirement.
Back to article page