In Haskell, is it possible to pattern match on functions that have a type variable for the outer but not inner type? Here, for example, funky takes any type constructor that takes a Bar
. While this works for destructuring the two cases, I'm not sure how to write the global case on the bottom, which should ideally return the result of the destructuring. I've put a question mark before q
because that's what's stumping me - I'm not sure how to destructure that last pattern match to get the Bar
out. Thanks in advance for your help!
data Bar = Bar
data Foo = AA Bar | BB Bar | CC Bar | DD Bar
funky :: x Bar -> Bar
funky (AA z) = z
funky (BB z) = z
funky (? q) = q