File tree Expand file tree Collapse file tree 3 files changed +26
-14
lines changed Expand file tree Collapse file tree 3 files changed +26
-14
lines changed Original file line number Diff line number Diff line change @@ -26,11 +26,12 @@ data PhoneType
2626 | OtherPhone
2727
2828-- ANCHOR: PhoneType_generic
29- derive instance genericPhoneType :: Generic PhoneType _
30- instance encodeJsonPhoneType :: EncodeJson PhoneType where encodeJson = genericEncodeJson
31- instance decodeJsonPhoneType :: DecodeJson PhoneType where decodeJson = genericDecodeJson
29+ derive instance genericPhoneType :: Generic PhoneType _
30+
31+ instance encodeJsonPhoneType :: EncodeJson PhoneType where encodeJson = genericEncodeJson
32+ instance decodeJsonPhoneType :: DecodeJson PhoneType where decodeJson = genericDecodeJson
3233-- ANCHOR_END: PhoneType_generic
33- instance showPhoneType :: Show PhoneType where show = genericShow
34+ instance showPhoneType :: Show PhoneType where show = genericShow
3435
3536type PhoneNumber
3637 = { "type" :: PhoneType
Original file line number Diff line number Diff line change 11module Data.AddressBook where
22
33import Prelude
4+ import Data.Generic.Rep (class Generic )
5+ import Data.Generic.Rep.Show (genericShow )
46
57type Address
68 = { street :: String
@@ -21,18 +23,26 @@ data PhoneType
2123 | OtherPhone
2224-- ANCHOR_END: PhoneType
2325
24- {-| derive has not been discussed yet but will be
25- covered in Ch 10. Here it is needed by the unit
26- tests to define how to compare the PhoneType values
26+ {-
27+ Eq and Show instances are needed by unit tests to
28+ compare and report differences between PhoneType values
2729(HomePhone, WorkPhone, etc).
2830-}
2931derive instance eqPhoneType :: Eq PhoneType
3032
33+ -- Generic Show instance
34+ derive instance genericPhoneType :: Generic PhoneType _
35+
36+ instance showPhoneType :: Show PhoneType where
37+ show = genericShow
38+ {-
39+ -- Manually-written Show instance
3140instance showPhoneType :: Show PhoneType where
32- show HomePhone = " HomePhone"
33- show WorkPhone = " WorkPhone"
34- show CellPhone = " CellPhone"
41+ show HomePhone = "HomePhone"
42+ show WorkPhone = "WorkPhone"
43+ show CellPhone = "CellPhone"
3544 show OtherPhone = "OtherPhone"
45+ -}
3646
3747type PhoneNumber
3848 = { "type" :: PhoneType
Original file line number Diff line number Diff line change 11module Data.AddressBook where
22
33import Prelude
4+ import Data.Generic.Rep (class Generic )
5+ import Data.Generic.Rep.Show (genericShow )
46
57type Address
68 = { street :: String
@@ -17,11 +19,10 @@ data PhoneType
1719 | CellPhone
1820 | OtherPhone
1921
22+ derive instance genericPhoneType :: Generic PhoneType _
23+
2024instance showPhoneType :: Show PhoneType where
21- show HomePhone = " HomePhone"
22- show WorkPhone = " WorkPhone"
23- show CellPhone = " CellPhone"
24- show OtherPhone = " OtherPhone"
25+ show = genericShow
2526
2627type PhoneNumber
2728 = { "type" :: PhoneType
You can’t perform that action at this time.
0 commit comments