Skip to content

Commit 5757cba

Browse files
committed
Minor documentation changes
1 parent 76db877 commit 5757cba

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

generic-diff-instances/src/Generics/Diff/Special/Map.hs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ data MapDiffError k v
3030
deriving (Show, Eq)
3131

3232
{- | Render a 'MapDiffError'. This is a top-level function because we'll use it in the implementations
33-
of 'renderSpecialDiffError' for both 'Map' and 'IntMap'.
33+
of 'renderSpecialDiffError' for both 'Map' and 'Data.IntMap.IntMap'.
3434
-}
3535
mapDiffErrorDoc :: (Show k) => MapDiffError k v -> Doc
3636
mapDiffErrorDoc = \case
@@ -43,9 +43,6 @@ mapDiffErrorDoc = \case
4343
RightMissingKey k ->
4444
linesDoc $ pure $ "The left map contains key " <> showB k <> " but the right doesn't"
4545

46-
------------------------------------------------------------
47-
-- Map
48-
4946
instance (Show k, Ord k, Diff v) => SpecialDiff (Map k v) where
5047
type SpecialDiffError (Map k v) = MapDiffError k v
5148

@@ -67,6 +64,5 @@ instance (Show k, Ord k, Diff v) => SpecialDiff (Map k v) where
6764

6865
renderSpecialDiffError = mapDiffErrorDoc
6966

70-
-- | Now we can implement 'Diff' using 'diffWithSpecial'.
7167
instance (Show k, Ord k, Diff v) => Diff (Map k v) where
7268
diff = diffWithSpecial

generic-diff-instances/src/Generics/Diff/Special/Set.hs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ data SetDiffError k
3131
deriving (Show, Eq)
3232

3333
{- | Render a 'SetDiffError'. This is a top-level function because we'll use it in the implementations
34-
of 'renderSpecialDiffError' for both 'Set' and 'IntSet'.
34+
of 'renderSpecialDiffError' for both 'Set' and 'Data.IntSet.IntSet'.
3535
3636
There are no nested 'DiffError's here, so we use 'linesDoc'.
3737
-}
@@ -42,9 +42,8 @@ setDiffErrorDoc = \case
4242
RightMissingKey k ->
4343
linesDoc $ pure $ "The left set contains key " <> showB k <> " but the right doesn't"
4444

45-
{- | First we define an instance of 'SpecialDiff'. We need 'Show' and 'Eq' so that 'SetDiffError'
46-
also has these instances; we need 'Ord' to compare elements of the set.
47-
-}
45+
-- First we define an instance of 'SpecialDiff'. We need 'Show' and 'Eq' so that 'SetDiffError'
46+
-- also has these instances; we need 'Ord' to compare elements of the set.
4847
instance (Show k, Eq k, Ord k) => SpecialDiff (Set k) where
4948
type SpecialDiffError (Set k) = SetDiffError k
5049

@@ -62,6 +61,6 @@ instance (Show k, Eq k, Ord k) => SpecialDiff (Set k) where
6261

6362
renderSpecialDiffError = setDiffErrorDoc
6463

65-
-- | Now we can implement 'Diff' using 'diffWithSpecial'.
64+
-- Now we can implement 'Diff' using 'diffWithSpecial'.
6665
instance (Show k, Ord k) => Diff (Set k) where
6766
diff = diffWithSpecial

generic-diff-instances/src/Generics/Diff/Special/Tree.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{-# LANGUAGE DerivingVia #-}
22
{-# OPTIONS_GHC -Wno-orphans #-}
33

4-
{- | A worked example of implementing 'SpecialDiff' (and thereby 'Diff') for 'Tree's.
4+
{- | A worked example of implementing 'SpecialDiff' (and thereby 'Diff') for 'Tree.Tree's.
55
66
As with other 3rd-party types, there are different approaches we can take here. We'll show 2 of them:
77
@@ -22,6 +22,7 @@ import Generics.SOP.GGP
2222
------------------------------------------------------------
2323
-- Using gspecialDiffNested
2424

25+
-- | Generically-derived instance.
2526
instance (Diff a) => SpecialDiff (Tree.Tree a) where
2627
type SpecialDiffError (Tree.Tree a) = DiffErrorNested (GCode (Tree.Tree a))
2728
specialDiff = gspecialDiffNested
@@ -33,17 +34,23 @@ instance (Diff a) => Diff (Tree.Tree a) where
3334
------------------------------------------------------------
3435
-- Using SpecialDiff
3536

37+
{- | A newtype wrapper around 'Tree.Tree' to demonstrate one alternate way we could hand-write
38+
a 'SpecialDiff' instance.
39+
-}
3640
newtype CustomTree a = CustomTree (Tree.Tree a)
3741
deriving (Show) via (Tree.Tree a)
3842

43+
-- | Where are we in the tree? Each element of the list says which child node we step to next.
3944
newtype TreePath = TreePath [Int]
4045
deriving (Show, Eq) via [Int]
4146

47+
-- | A custom error type for 'CustomTree'.
4248
data CustomTreeDiffError a
4349
= DiffAtNode TreePath (DiffError a)
4450
| WrongLengthsOfChildren TreePath Int Int
4551
deriving (Show, Eq)
4652

53+
-- | Render a tree path as a 'TB.Builder'
4754
renderTreePath :: TreePath -> TB.Builder
4855
renderTreePath (TreePath []) = "<root>"
4956
renderTreePath (TreePath (x : xs)) = mconcat $ showB x : ["->" <> showB y | y <- xs]

0 commit comments

Comments
 (0)