Created
November 25, 2020 15:14
-
-
Save xe-4/27c685e6d22e05251c1a653fec791926 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> :set -XDeriveGeneric | |
> :set -XGeneralizedNewtypeDeriving | |
> import GHC.Generics | |
> data Bar = Bar { baz :: Int, qux :: Int } deriving (Generic, Eq, Show) | |
> instance ToJSON Bar | |
> instance FromJSON Bar | |
> toJSON $ Bar 1 2 | |
Object (fromList [("baz",Number 1.0),("qux",Number 2.0)]) | |
> newtype Foo = Foo Bar deriving (Generic, Eq, Show) | |
> instance ToJSON Foo | |
> instance FromJSON Foo | |
> toJSON . Foo $ Bar 1 2 | |
Object (fromList [("baz",Number 1.0),("qux",Number 2.0)]) | |
> :set -XDerivingStrategies | |
> :{ | |
newtype Zoo = Zoo Bar | |
deriving stock Generic | |
deriving newtype (Eq, Show) | |
:} | |
> instance ToJSON Zoo | |
> instance FromJSON Zoo | |
> toJSON . Zoo $ Bar 1 2 | |
Object (fromList [("baz",Number 1.0),("qux",Number 2.0)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment