Skip to content

Commit 23e4872

Browse files
authored
fix: AsType haddocks hide code examples (#165)
* fix: haddock syntax error This was hiding the initial datatypes for the instance examples, which made them very confusing * feat: add repl examples for other instance methods
1 parent cbe168c commit 23e4872

File tree

2 files changed

+41
-4
lines changed
  • generic-lens/src/Data/Generics/Sum
  • generic-optics/src/Data/Generics/Sum

2 files changed

+41
-4
lines changed

generic-lens/src/Data/Generics/Sum/Typed.hs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
module Data.Generics.Sum.Typed
2828
( -- *Prisms
2929
--
30-
-- $setup
30+
-- $setup
3131
AsType (..)
3232
) where
3333

@@ -61,7 +61,7 @@ import "generic-lens-core" Data.Generics.Internal.Void
6161
-- dog = Dog (MkDog "Shep" (Age 3))
6262
-- cat = Cat "Mog" (Age 5)
6363
-- duck = Duck (Age 2)
64-
-- :}
64+
-- >>> :}
6565

6666

6767
-- |Types that can represent another type, either by being a sum with a
@@ -87,11 +87,29 @@ class AsType a s where
8787
{-# INLINE _Typed #-}
8888

8989
-- |Inject by type.
90+
--
91+
--
92+
-- >>> :{
93+
-- dog :: Dog
94+
-- dog = MkDog "Fido" (Age 11)
95+
-- dogAsAnimal :: Animal
96+
-- dogAsAnimal = injectTyped dog
97+
-- dogAsItself :: Dog
98+
-- dogAsItself = injectTyped dog
99+
-- >>> :}
90100
injectTyped :: a -> s
91101
injectTyped
92102
= build _Typed
93103

94104
-- |Project by type.
105+
--
106+
--
107+
-- >>> :{
108+
-- dogAsAnimal :: Animal
109+
-- dogAsAnimal = Dog (MkDog "Fido (Age 11)")
110+
-- mDog :: Maybe Dog
111+
-- mDog = projectTyped dogAsAnimal
112+
-- >>> :}
95113
projectTyped :: s -> Maybe a
96114
projectTyped
97115
= either (const Nothing) Just . match _Typed

generic-optics/src/Data/Generics/Sum/Typed.hs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
module Data.Generics.Sum.Typed
2828
( -- *Prisms
2929
--
30-
-- $setup
30+
-- $setup
3131
AsType (..)
3232
) where
3333

@@ -86,12 +86,31 @@ class AsType a s where
8686
_Typed = prism injectTyped (\i -> maybe (Left i) Right (projectTyped i))
8787
{-# INLINE _Typed #-}
8888

89+
8990
-- |Inject by type.
91+
--
92+
--
93+
-- >>> :{
94+
-- dog :: Dog
95+
-- dog = MkDog "Fido" (Age 11)
96+
-- dogAsAnimal :: Animal
97+
-- dogAsAnimal = injectTyped dog
98+
-- dogAsItself :: Dog
99+
-- dogAsItself = injectTyped dog
100+
-- >>> :}
90101
injectTyped :: a -> s
91102
injectTyped
92-
= review _Typed
103+
= build _Typed
93104

94105
-- |Project by type.
106+
--
107+
--
108+
-- >>> :{
109+
-- dogAsAnimal :: Animal
110+
-- dogAsAnimal = Dog (MkDog "Fido (Age 11)")
111+
-- mDog :: Maybe Dog
112+
-- mDog = projectTyped dogAsAnimal
113+
-- >>> :}
95114
projectTyped :: s -> Maybe a
96115
projectTyped
97116
= either (const Nothing) Just . matching _Typed

0 commit comments

Comments
 (0)