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

Constraint missing on type parameter #74

Open
flip111 opened this issue Feb 18, 2023 · 3 comments
Open

Constraint missing on type parameter #74

flip111 opened this issue Feb 18, 2023 · 3 comments

Comments

@flip111
Copy link

flip111 commented Feb 18, 2023

deriving instance Eq A

data Maybe' a = Nothing' | Just' a
  deriving (Generic, Eq)

myTypes :: [SumType 'Haskell]
myTypes =
  [ let p = (Proxy :: Proxy (Maybe' A)) in equal p (mkSumType p)
  ]

run :: IO ()
run = writePSTypes "/home/flip111/types" (buildBridge defaultBridge) myTypes

The generated purescript code looks like this

data Maybe' a =
    Nothing'
  | Just' a

derive instance eqMaybe' :: Eq (Maybe' a)

But instead the instance should be like this

derive instance eqMaybe' :: Eq a => Eq (Maybe' a)
@peterbecich
Copy link
Contributor

@flip111 , here is a similar issue that appears in #77

Given this

import Data.Either (Either)
import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe(..))
import Data.Newtype (class Newtype)

data Bar a b m c
  = Bar1 (Maybe a)
  | Bar2 (Either a b)
  | Bar3 a
  | Bar4 { myMonadicResult :: m b }

should purescript-bridge generate this?

derive instance (Generic a ra, Generic b rb, Generic (m b) rmb) => Generic (Bar a b m c) _

or this?

derive instance Generic (Bar a b m c) _

Thanks

@eskimor
Copy link
Owner

eskimor commented Apr 6, 2023

I think we will need some means of telling the code generator what is correct. There are cases where you want the constraint on the type parameters, sometimes you don't. Depends very much on the type class at hand and the type.

@flip111
Copy link
Author

flip111 commented Apr 6, 2023

@peterbecich i'm not sure. Could you pass flag -ddump-deriv to GHC and paste the haskell code for the Generic implementation?

peterbecich added a commit to peterbecich/purescript-bridge that referenced this issue Sep 25, 2023
* `CodeGenSwitches` no longer used
* `Proxy` no longer used
* `Printer` uses `Leijen.Text` instead of `Text`
* some unit tests replaced with IOHK's tests

TODO
* fix derived instances
  * eskimor#74 (comment)
* fix tests
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

No branches or pull requests

3 participants