@@ -9,14 +9,13 @@ module PrismsForSumTypes where
99 preview prismForSolidFill $ Solid Color.white
1010 -- (Just rgba 255 255 255 1.0)
1111
12- preview prismForSolidCase NoFill
12+ preview prismForSolidFill NoFill
1313 -- Nothing
1414
1515 review prismForSolidFill Color.white
1616 -- (Solid rgba 255 255 255 1.0)
1717-}
1818
19-
2019{- If you want to try out examples, paste the following into the repl.
2120
2221import PrismsForSumTypes
@@ -27,10 +26,8 @@ import Data.Maybe
2726import Data.Record.ShowRecord (showRecord)
2827
2928See `README.md` if you're wondering why code is formatted the way it is.
30-
3129-}
3230
33-
3431import Prelude
3532import Data.Lens (Prism' , is , isn't , nearly , only , preview , prism , prism' , review )
3633
@@ -68,26 +65,6 @@ fillRadial :: Fill
6865fillRadial = RadialGradient Color .white Color .black $ Point 1.0 3.4
6966
7067
71- {- ----- Eq and Show come in handy ------}
72-
73- derive instance genericPercent :: Generic Percent _
74- instance eqPercent :: Eq Percent where
75- eq = GEq .genericEq
76- instance showPercent :: Show Percent where
77- show (Percent f) = " (" <> show f <> " %)"
78-
79- derive instance genericPoint :: Generic Point _
80- instance eqPoint :: Eq Point where
81- eq = GEq .genericEq
82- instance showPoint :: Show Point where
83- show (Point x y) = " (" <> show x <> " , " <> show y <> " )"
84-
85- derive instance genericFill :: Generic Fill _
86- instance eqFill :: Eq Fill where
87- eq = GEq .genericEq
88- instance showFill :: Show Fill where
89- show x = GShow .genericShow x
90-
9168
9269 {- ----- Making prisms with Maybe and `prism'` ------}
9370
@@ -204,6 +181,10 @@ o3 :: Boolean
204181o3 = is whiteToBlackFocus fillRadial :: Boolean
205182-- false
206183
184+ -- Note that `only` requires `Fill` to implement `Eq`.
185+ -- It's the only prism constructor that does.
186+
187+
207188-- `nearly` is typically used to look for a specific case (like other
208189-- prisms), but also accepts only values that are close to some target
209190-- value. It takes two values: a reference value, and a predicate that
@@ -251,3 +232,27 @@ n4 = is brightSolidFocus (Solid Color.white) :: Boolean
251232n5 :: Fill
252233n5 = review brightSolidFocus unit
253234-- (Solid rgba 204 204 204 1.0)
235+
236+
237+
238+ {- ----- Eq and Show are always nice ------}
239+
240+ -- ... although Eq is only required for `only`.
241+
242+ derive instance genericPercent :: Generic Percent _
243+ instance eqPercent :: Eq Percent where
244+ eq = GEq .genericEq
245+ instance showPercent :: Show Percent where
246+ show (Percent f) = " (" <> show f <> " %)"
247+
248+ derive instance genericPoint :: Generic Point _
249+ instance eqPoint :: Eq Point where
250+ eq = GEq .genericEq
251+ instance showPoint :: Show Point where
252+ show (Point x y) = " (" <> show x <> " , " <> show y <> " )"
253+
254+ derive instance genericFill :: Generic Fill _
255+ instance eqFill :: Eq Fill where
256+ eq = GEq .genericEq
257+ instance showFill :: Show Fill where
258+ show x = GShow .genericShow x
0 commit comments