@@ -8,6 +8,7 @@ module Ormolu.Printer.Meat.Declaration.Instance
8 ( p_clsInstDecl
8 ( p_clsInstDecl
9 , p_tyFamInstDecl
9 , p_tyFamInstDecl
10 , p_dataFamInstDecl
10 , p_dataFamInstDecl
11+ , p_standaloneDerivDecl
@@ -26,16 +27,47 @@ import Ormolu.Printer.Meat.Declaration.Value
26import Ormolu.Printer.Meat.Type
27import Ormolu.Printer.Meat.Type
27import Ormolu.Utils
28import Ormolu.Utils
30+p_standaloneDerivDecl :: DerivDecl GhcPs -> R ()
31+p_standaloneDerivDecl DerivDecl {..} = do
32+ let typesAfterInstance = located (hsib_body (hswc_body deriv_type)) p_hsType
33+ instTypes toIndent = inci $ do
36+ match_overlap_mode deriv_overlap_mode breakpoint
38+ then inci typesAfterInstance
39+ else typesAfterInstance
41+ case deriv_strategy of
45+ Just l -> locatedVia Nothing l $ \case
49+ AnyclassStrategy -> do
52+ NewtypeStrategy -> do
55+ ViaStrategy HsIB {..} -> do
58+ inci (located hsib_body p_hsType)
61+ ViaStrategy (XHsImplicitBndrs NoExt) ->
62+ notImplemented "XHsImplicitBndrs"
64+p_standaloneDerivDecl (XDerivDecl _) = notImplemented "XDerivDecl"
29p_clsInstDecl :: ClsInstDecl GhcPs -> R ()
66p_clsInstDecl :: ClsInstDecl GhcPs -> R ()
30p_clsInstDecl = \case
67p_clsInstDecl = \case
31 ClsInstDecl {..} -> do
68 ClsInstDecl {..} -> do
32 txt "instance "
69 txt "instance "
33− case unLoc <$> cid_overlap_mode of
70+ match_overlap_mode cid_overlap_mode space
34− Just Overlappable {} -> txt "{-# OVERLAPPABLE #-} "
35− Just Overlapping {} -> txt "{-# OVERLAPPING #-} "
36− Just Overlaps {} -> txt "{-# OVERLAPS #-} "
37− Just Incoherent {} -> txt "{-# INCOHERENT #-} "
39 case cid_poly_ty of
71 case cid_poly_ty of
40 HsIB {..} -> sitcc (located hsib_body p_hsType)
72 HsIB {..} -> sitcc (located hsib_body p_hsType)
41 XHsImplicitBndrs NoExt -> notImplemented "XHsImplicitBndrs"
73 XHsImplicitBndrs NoExt -> notImplemented "XHsImplicitBndrs"
@@ -81,3 +113,20 @@ p_dataFamInstDecl style = \case
81 let HsIB {..} = dfid_eqn
113 let HsIB {..} = dfid_eqn
82 FamEqn {..} = hsib_body
114 FamEqn {..} = hsib_body
83 p_dataDecl style feqn_tycon feqn_pats feqn_rhs
115 p_dataDecl style feqn_tycon feqn_pats feqn_rhs
117+match_overlap_mode :: Maybe (Located OverlapMode) -> R () -> R ()
118+match_overlap_mode overlap_mode layoutStrategy =
119+ case unLoc <$> overlap_mode of
120+ Just Overlappable {} -> do
121+ txt "{-# OVERLAPPABLE #-}"
123+ Just Overlapping {} -> do
124+ txt "{-# OVERLAPPING #-}"
126+ Just Overlaps {} -> do
127+ txt "{-# OVERLAPS #-}"
129+ Just Incoherent {} -> do
130+ txt "{-# INCOHERENT #-}"