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

RowParser parameter has nominal role #102

Open
Shimuuar opened this issue May 23, 2022 · 2 comments
Open

RowParser parameter has nominal role #102

Shimuuar opened this issue May 23, 2022 · 2 comments

Comments

@Shimuuar
Copy link
Contributor

This makes it impossible to use GND or deriving via to derive FromRow instances. This is rather annoying since there is no good reason for type variable to nominal.

Fixing this is possible but require some boilerplate

@jchia
Copy link
Collaborator

jchia commented Jan 14, 2024

To motivate the discussion and possible solution, do you have a code sample with error messages illustrating the problem to solve?

@Shimuuar
Copy link
Contributor Author

As I said it makes impossible to use GND or deriving via which rely on coerce. As a simple example:

newtype Foo = Foo (Int,Int)
  deriving newtype FromRow

results in error:

    • Couldn't match type ‘(Int, Int)’ with ‘Foo’
        arising from the coercion of the method ‘fromRow’
          from type ‘RowParser (Int, Int)’ to type ‘RowParser Foo’
    • When deriving the instance for (FromRow Foo)

Reason for that is quite easy to see:

type role RowParser nominal

This in turn is caused by ReaderT:

type role ReaderT representational representational nominal

This could be fixed by unpacking ReaderT and using it only to derive instances. Something along the lines:

newtype RowParser a = RP { unRP :: ReaderT RowParseRO (StateT (Int, [Base.SQLData]) Ok) a }
   deriving ( Functor, Applicative, Alternative, Monad, MonadPlus )

newtype RowParser a = RP { unRP :: RowParseRO -> StateT (Int, [Base.SQLData]) Ok a }
   deriving ( Functor, Applicative, Alternative, Monad, MonadPlus ) via ReaderT RowParseRO (StateT (Int, [Base.SQLData]) Ok) a

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

2 participants