11module PrismsForSumTypes where
22
3- {-
4-
5- If you want to try out examples, paste the following into the repl.
6-
7- import Data.Maybe
3+ {- If you want to try out examples, paste the following into the repl.
84
5+ import PrismsForSumTypes
96import Data.Lens
107import Data.Lens.Prism
118import Color as Color
9+ import Data.Maybe
1210import Data.Record.ShowRecord (showRecord)
13- import PrismsForSumTypes
11+
12+ Examples are written in this format:
13+
14+ s1 :: Maybe Color
15+ s1 = preview solidFocus (Solid Color.white) -- (Just rgba 255 255 255 1.0)
16+
17+ That's so that a typical syntax highlighter will make the executable code
18+ easy to spot among the commentary. (The name-value binding is unfortunate,
19+ but needed to prevent noise from compiler warnings.)
1420
1521-}
1622
@@ -39,7 +45,7 @@ data Fill
3945 | RadialGradient Color Color Point
4046 | NoFill
4147
42- {- Some samples to work with -}
48+ {- ----- Some samples to work with ----- -}
4349
4450fillWhite :: Fill
4551fillWhite = Solid Color .white
@@ -54,7 +60,7 @@ fillRadial :: Fill
5460fillRadial = RadialGradient Color .white Color .black $ Point 1.0 3.4
5561
5662
57- {- Eq and Show come in handy -}
63+ {- ----- Eq and Show come in handy ----- -}
5864
5965derive instance genericPercent :: Generic Percent _
6066instance eqPercent :: Eq Percent where
@@ -75,8 +81,8 @@ instance showFill :: Show Fill where
7581 show x = GShow .genericShow x
7682
7783
78- {- Making prisms with Maybe and `prism'`-}
79- {- Basic usage -}
84+ {- ----- Making prisms with Maybe and `prism'` ----- -}
85+ {- ----- Basic usage ----- -}
8086
8187-- Two function arguments: a data constructor for the type in
8288-- question, plus one that "substitutes" your desired case with `Just`
@@ -123,7 +129,7 @@ s5 = isn't solidFocus fillWhite :: Boolean -- false
123129
124130
125131
126- {- Making prisms with Either and `prism` -}
132+ {- ----- Making prisms with Either and `prism` ----- -}
127133
128134-- Since `LinearGradient` wraps multiple values, they need to be
129135-- rewrapped for `preview`. I'll use a record.
@@ -162,7 +168,7 @@ l2 = review linearFocus { color1 : Color.black
162168 , percent : Percent 33.3
163169 }
164170
165- {- Constructing more specific prisms -}
171+ {- ----- Constructing more specific prisms ----- -}
166172
167173-- `only` is used to check for a specific value:
168174
0 commit comments