Skip to content

Commit

Permalink
work-in-progress purescript-argonaut-aeson-generic instances
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbecich committed Apr 9, 2023
1 parent b8ce119 commit c2ee7e8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Language/PureScript/Bridge/Printer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,19 @@ instances st@(SumType t _ is) = go <$> is
decodeJsonConstraints
[hang 2 $ "decodeJson = defer \\_ -> D.decode" <+> sumTypeToDecode st]
]
go ArgonautAesonGeneric =
vsep $
punctuate
line
[ mkInstance
(mkType "EncodeJson" [t])
encodeJsonConstraints
["encodeJson = genericEncodeAeson Argonaut.defaultOptions"],
mkInstance
(mkType "DecodeJson" [t])
decodeJsonConstraints
["decodeJson = genericDecodeAeson Argonaut.defaultOptions"]
]
go Foreign = mempty -- Foreign Generic uses `Generic` below
go GenericShow = mkInstance (mkType "Show" [t]) showConstraints ["show a = genericShow a"]
go Functor = mkDerivedInstance (mkType "Functor" [toKind1 t]) (const [])
Expand Down
6 changes: 6 additions & 0 deletions src/Language/PureScript/Bridge/SumType.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ data Instance (lang :: Language)
= Generic
| GenericShow
| Json
| ArgonautAesonGeneric
| Foreign
| Newtype
| Functor
Expand Down Expand Up @@ -269,6 +270,11 @@ instanceToTypes Json =
<$> [ TypeInfo "purescript-argonaut-codecs" "Data.Argonaut.Decode" "DecodeJson" []
, TypeInfo "purescript-argonaut-codecs" "Data.Argonaut.Encode" "EncodeJson" []
]
instanceToTypes ArgonautAesonGeneric =
constraintToType
<$> [ TypeInfo "purescript-argonaut-aeson-generic" "Data.Argonaut.Aeson.Decode.Generic" "DecodeJson" []
, TypeInfo "purescript-argonaut-aeson-generic" "Data.Argonaut.Aeson.Encode.Generic" "EncodeJson" []
]
instanceToTypes Foreign =
constraintToType
<$> [ TypeInfo "purescript-foreign" "Foreign" "Foreign" []
Expand Down

0 comments on commit c2ee7e8

Please sign in to comment.