I'm trying to simplify a composite data type, but don't know the best way. Here is my code so far:
data Init a b c d = Init a b c d
data Wrap a = WNil (Init a b c d)
| WCons a (Wrap a)
The issue I keep seeing is probably obvious - I can't unify the expected result type's type variables with the encapsulated one:
-- | Will fail to compile
unWrap :: Wrap a -> Init a b c d
unWrap (WNil x) = x
unWrap (WCons _ xs) = unWrap xs
I've heard -XExistentialQuantification
thrown around as a possible solution, but I couldn't get anything working. Does anyone have an idea what to do here, besides floating the type parameters to Wrap
?