-mkNewTypeEqn orig gla_exts overlap_flag tvs cls cls_tys
- tycon tc_args
- rep_tycon rep_tc_args
- | can_derive_via_isomorphism && (gla_exts || std_class_via_iso cls)
- = do { traceTc (text "newtype deriving:" <+> ppr tycon <+> ppr rep_tys)
- ; -- Go ahead and use the isomorphism
- dfun_name <- new_dfun_name cls tycon
- ; return (Nothing, Just (InstInfo { iSpec = mk_inst_spec dfun_name,
- iBinds = NewTypeDerived ntd_info })) }
- | std_class gla_exts cls
- = mkDataTypeEqn orig gla_exts tvs cls cls_tys tycon tc_args rep_tycon rep_tc_args -- Go via bale-out route
-
- -- Otherwise its a non-standard instance
- | gla_exts = baleOut cant_derive_err -- Too hard
- | otherwise = baleOut non_std_err -- Just complain about being a non-std instance
+mkNewTypeEqn :: InstOrigin -> Bool -> Bool -> OverlapFlag -> [Var] -> Class
+ -> [Type] -> TyCon -> [Type] -> TyCon -> [Type]
+ -> Maybe DerivRhs
+ -> TcRn (Maybe DerivEqn, Maybe InstInfo)
+mkNewTypeEqn orig mayDeriveDataTypeable newtype_deriving overlap_flag tvs
+ cls cls_tys tycon tc_args rep_tycon rep_tc_args mtheta
+ | can_derive_via_isomorphism && (newtype_deriving || std_class_via_iso cls)
+ = do { traceTc (text "newtype deriving:" <+> ppr tycon <+> ppr rep_tys)
+ ; -- Go ahead and use the isomorphism
+ dfun_name <- new_dfun_name cls tycon
+ ; return (Nothing, Just (InstInfo { iSpec = mk_inst_spec dfun_name,
+ iBinds = NewTypeDerived ntd_info })) }
+
+ | isNothing mb_std_err -- Use the standard H98 method
+ = do { loc <- getSrcSpanM
+ ; eqn <- mk_data_eqn loc orig tvs cls tycon tc_args rep_tycon
+ rep_tc_args mtheta
+ ; return (Just eqn, Nothing) }
+
+ -- Otherwise we can't derive
+ | newtype_deriving = baleOut cant_derive_err -- Too hard
+ | otherwise = baleOut std_err -- Just complain about being a non-std instance