@@ -17,6 +17,7 @@ import Data.List (foldl', find, sortBy)
1717import Data.Maybe (fromMaybe)
1818import Data.Ord (comparing)
1919
20+import Control.Arrow (second)
2021import Control.Monad (replicateM)
2122import Control.Monad.Supply.Class (MonadSupply)
2223import Control.Monad.Error.Class (MonadError(..))
@@ -55,11 +56,13 @@ deriveInstance mn ds (PositionedDeclaration pos com d) = PositionedDeclaration p
5556deriveInstance _ _ e = return e
5657
5758unwrapTypeConstructor :: Type -> Maybe (Qualified (ProperName 'TypeName), [Type])
58−unwrapTypeConstructor (TypeConstructor tyCon) = Just (tyCon, [])
59−unwrapTypeConstructor (TypeApp ty arg) = do
60− (tyCon, args) <- unwrapTypeConstructor ty
61− return (tyCon, arg : args)
62−unwrapTypeConstructor _ = Nothing
59+unwrapTypeConstructor = fmap (second reverse) . go
60+ where
61+ go (TypeConstructor tyCon) = Just (tyCon, [])
62+ go (TypeApp ty arg) = do
63+ (tyCon, args) <- go ty
64+ return (tyCon, arg : args)
65+ go _ = Nothing
6366
6467dataGeneric :: ModuleName
6568dataGeneric = ModuleName [ ProperName "Data", ProperName "Generic" ]