@@ -2,12 +2,12 @@
22{-# LANGUAGE OverloadedStrings #-}
33{-# LANGUAGE RecordWildCards #-}
44
5−-- | Type class instance declarations.
5+-- | Type class, type family, and data family instance declarations.
66
77module Ormolu.Printer.Meat.Declaration.Instance
88 ( p_clsInstDecl
9− , FamilyStyle (Associate, Free)
109 , p_tyFamInstDecl
10+ , p_dataFamInstDecl
1111 )
1212where
1313
@@ -18,6 +18,8 @@ import Data.Function
1818import Data.List (sortBy)
1919import GHC
2020import Ormolu.Printer.Combinators
21+import Ormolu.Printer.Meat.Common
22+import Ormolu.Printer.Meat.Declaration.Data
2123import Ormolu.Printer.Meat.Declaration.Signature
2224import Ormolu.Printer.Meat.Declaration.TypeFamily
2325import Ormolu.Printer.Meat.Declaration.Value
@@ -44,10 +46,16 @@ p_clsInstDecl = \case
4446 let binds = (getLoc &&& located' p_valDecl) <$> cid_binds
4547 sigs = (getLoc &&& located' p_sigDecl) <$> cid_sigs
4648 tyfam_insts =
47− (getLoc &&& located' (p_tyFamInstDecl Associate)) <$> cid_tyfam_insts
49+ (getLoc &&& located' (p_tyFamInstDecl Associated)) <$>
50+ cid_tyfam_insts
51+ datafam_insts =
52+ (getLoc &&& located' (p_dataFamInstDecl Associated)) <$>
53+ cid_datafam_insts
4854 decls =
4955 snd <$>
50− sortBy (compare `on` fst) (toList binds <> sigs <> tyfam_insts)
56+ sortBy
57+ (compare `on` fst)
58+ (toList binds <> sigs <> tyfam_insts <> datafam_insts)
5159 if not (null decls)
5260 then do
5361 txt " where"
@@ -57,15 +65,18 @@ p_clsInstDecl = \case
5765 newline
5866 XClsInstDecl NoExt -> notImplemented "XClsInstDecl"
5967
60−data FamilyStyle
61− = Associate
62− | Free
63−
6468p_tyFamInstDecl :: FamilyStyle -> TyFamInstDecl GhcPs -> R ()
6569p_tyFamInstDecl style = \case
6670 TyFamInstDecl {..} -> do
6771 txt $ case style of
68− Associate -> "type "
72+ Associated -> "type "
6973 Free -> "type instance "
7074 p_tyFamInstEqn tfid_eqn
7175 newline
76+
77+p_dataFamInstDecl :: FamilyStyle -> DataFamInstDecl GhcPs -> R ()
78+p_dataFamInstDecl style = \case
79+ DataFamInstDecl {..} -> do
80+ let HsIB {..} = dfid_eqn
81+ FamEqn {..} = hsib_body
82+ p_dataDecl style feqn_tycon feqn_pats feqn_rhs