Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge IOHK fork #77

Closed

Conversation

peterbecich
Copy link
Contributor

@peterbecich peterbecich commented Mar 20, 2023

Closes #63

Uses https://hackage.haskell.org/package/wl-pprint-text-1.2.0.2

Merge is not complete yet

shmish111 and others added 30 commits May 8, 2019 16:17
For generic decoding, `Decode (Foo a)` needs a `Decode a` constraint,
but it *doesn't* need a `Generic a` constraint.

Adding in this unnecessary constraint creates needless problems like,
"there isn't an instance for `Generic String _`."
PureScript isn't happy with eta-reduced typeclass instances on recursive
types. We have to make the function application explicit.
…y (Container A)`.

The generated code will include an `Eq a =>` constraint.
* Sum types where every constructor has zero arguments. Aeson has
special handling for these.
For generic decoding, `Decode (Foo a)` needs a `Decode a` constraint,
but it *doesn't* need a `Generic a` constraint.

Adding in this unnecessary constraint creates needless problems like,
"there isn't an instance for `Generic String _`."
…xy (Container A)`.

The generated code will include an `Ord a =>` constraint.
It turns out you can't eta-reduce typeclass instances for
recursively-defined typeclasses in PureScript. That is:

`show = genericShow`

...has to be replaced with:

`show x = genericShow`

...to work reliably.

See: purescript/purescript#2975
That is, `(genericShow <*> mkSumType) (Proxy @(Foo A))` will generate:

```
instance showFoo :: Show a => Show (Foo a) where
  show = genericShow
```

...whereas before it would have missed out the `Show a` constraint.
@peterbecich
Copy link
Contributor Author

TODO DecodeJsonField
c55622e
c0dbf86

@peterbecich
Copy link
Contributor Author

TODO fix type error in example. See spago build

@peterbecich
Copy link
Contributor Author

TODO #74 (comment)

@flip111
Copy link

flip111 commented May 5, 2023

When i load the code into GHCI i get

Not in scope: type constructor or class ‘Eq’
Not in scope: type constructor or class ‘Ord’
Not in scope: type constructor or class ‘Show’

for file https://github.com/peterbecich/purescript-bridge/blob/f1c0879094be41b3e6ef6846db00a28e461ef35a/src/Language/PureScript/Bridge/TypeInfo.hs

import Data.Eq (Eq)

fixed it for me

@peterbecich
Copy link
Contributor Author

@flip111 , I don't see that error.

Are you on GHC 9.2 or higher? If not, would you try using the Nix Flake?

nix develop will provide GHC 9.2. Then cabal repl.

@peterbecich
Copy link
Contributor Author

More detail about #77 (comment)

Using the parent repository currently, Haskell

data Bar a = Bar a
  deriving (Generic, Show, Typeable, FromJSON, ToJSON)

generates PureScript

newtype Bar a =
    Bar a

instance encodeJsonBar :: (Generic a ra, EncodeJson a) => EncodeJson (Bar a) where
  encodeJson = genericEncodeAeson Argonaut.defaultOptions
instance decodeJsonBar :: (Generic a ra, DecodeJson a, DecodeJsonField a) => DecodeJson (Bar a) where
  decodeJson = genericDecodeAeson Argonaut.defaultOptions
  
_Bar :: forall a. Iso' (Bar a) a
_Bar = _Newtype

That is correct.

In this PR,

data BarSimple a = BarSimple a
  deriving (Generic, Show, Typeable, FromJSON, ToJSON)

generates PureScript

newtype BarSimple a = BarSimple a

instance (Show a) => Show (BarSimple a) where
  show a = genericShow a

derive instance (Eq a) => Eq (BarSimple a)

derive instance (Ord a) => Ord (BarSimple a)

derive instance Newtype (BarSimple a) _

derive instance Generic (BarSimple a) _

instance (EncodeJson a) => EncodeJson (BarSimple a) where
  encodeJson = genericEncodeAeson Argonaut.defaultOptions

instance (DecodeJson a) => DecodeJson (BarSimple a) where
  decodeJson = genericDecodeAeson Argonaut.defaultOptions

. DecodeJsonField is missing

fix build of `RoundTrip` test

format tweaks

remove deprecated `Generics` library

WIP fixing tests

copy unit tests from IOHK fork

fixing tests

clean-up

fix Newtype, Lens imports

fixing tests

fix

remove duplicate tests

improve `CodeGenSwitches`

work-in-progress `purescript-argonaut-aeson-generic` instances

https://pursuit.purescript.org/packages/purescript-argonaut-aeson-generic/0.4.1

fix argonaut-aeson-generic support

improve ordering of printed instances

fix spaces

prisms and lenses

more test fixing

fix `Maybe(..)` import

fix line printing

fix Newtype imports

fix explicit aliased imports

fix `Lens'` and `Newtype` imports

fix example

fix RoundTrip test

lint

disable certain warnings

type parameters in `example`

`spago` compiles example successfully

`DecodeJsonField` eskimor@c55622e is not
supported yet

We want the result to be the same as https://github.com/eskimor/purescript-bridge/blob/ee0582aed3e5b62ea25b1079dee2c31b949381e7/example/src/Types.purs#L88-L93
@peterbecich
Copy link
Contributor Author

replaced by #89

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upstream IOHK fork of this library if possible
6 participants