@@ -2,12 +2,12 @@
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE RecordWildCards #-}
3{-# LANGUAGE RecordWildCards #-}
5−-- | Type class instance declarations.
5+-- | Type class, type family, and data family instance declarations.
7module Ormolu.Printer.Meat.Declaration.Instance
7module Ormolu.Printer.Meat.Declaration.Instance
8 ( p_clsInstDecl
8 ( p_clsInstDecl
9− , FamilyStyle (Associate, Free)
10 , p_tyFamInstDecl
9 , p_tyFamInstDecl
@@ -18,6 +18,8 @@ import Data.Function
18import Data.List (sortBy)
18import Data.List (sortBy)
20import Ormolu.Printer.Combinators
20import Ormolu.Printer.Combinators
21+import Ormolu.Printer.Meat.Common
22+import Ormolu.Printer.Meat.Declaration.Data
21import Ormolu.Printer.Meat.Declaration.Signature
23import Ormolu.Printer.Meat.Declaration.Signature
22import Ormolu.Printer.Meat.Declaration.TypeFamily
24import Ormolu.Printer.Meat.Declaration.TypeFamily
23import Ormolu.Printer.Meat.Declaration.Value
25import Ormolu.Printer.Meat.Declaration.Value
@@ -44,10 +46,16 @@ p_clsInstDecl = \case
44 let binds = (getLoc &&& located' p_valDecl) <$> cid_binds
46 let binds = (getLoc &&& located' p_valDecl) <$> cid_binds
45 sigs = (getLoc &&& located' p_sigDecl) <$> cid_sigs
47 sigs = (getLoc &&& located' p_sigDecl) <$> cid_sigs
46 tyfam_insts =
48 tyfam_insts =
47− (getLoc &&& located' (p_tyFamInstDecl Associate)) <$> cid_tyfam_insts
49+ (getLoc &&& located' (p_tyFamInstDecl Associated)) <$>
52+ (getLoc &&& located' (p_dataFamInstDecl Associated)) <$>
50− sortBy (compare `on` fst) (toList binds <> sigs <> tyfam_insts)
58+ (toList binds <> sigs <> tyfam_insts <> datafam_insts)
51 if not (null decls)
59 if not (null decls)
53 txt " where"
61 txt " where"
@@ -57,15 +65,18 @@ p_clsInstDecl = \case
58 XClsInstDecl NoExt -> notImplemented "XClsInstDecl"
66 XClsInstDecl NoExt -> notImplemented "XClsInstDecl"
64p_tyFamInstDecl :: FamilyStyle -> TyFamInstDecl GhcPs -> R ()
68p_tyFamInstDecl :: FamilyStyle -> TyFamInstDecl GhcPs -> R ()
65p_tyFamInstDecl style = \case
69p_tyFamInstDecl style = \case
66 TyFamInstDecl {..} -> do
70 TyFamInstDecl {..} -> do
67 txt $ case style of
71 txt $ case style of
68− Associate -> "type "
72+ Associated -> "type "
69 Free -> "type instance "
73 Free -> "type instance "
70 p_tyFamInstEqn tfid_eqn
74 p_tyFamInstEqn tfid_eqn
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