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

Using row kinds in instance declarations #2196

Closed
daniel-chambers opened this issue Jun 16, 2016 · 1 comment
Closed

Using row kinds in instance declarations #2196

daniel-chambers opened this issue Jun 16, 2016 · 1 comment

Comments

@daniel-chambers
Copy link

The PureScript compiler seems to prevent the following monadMine instance from being created:

import Prelude
import Control.Monad.Aff (Aff)
import Network.HTTP.Affjax (AJAX)

class Monad m <= MonadMine m where
  test :: Unit -> m Unit

instance monadMine :: MonadMine (Aff (ajax :: AJAX | e)) where
  test _ = pure unit

(ignore that the ajax effect isn't actually used in the instance, that's just for simplifying the example. Imagine replacing the pure unit call with something that requires that effect)

It gives the following error:

Type class instance head is invalid due to use of type at line 8 col 1
    ( ajax :: AJAX
    | e
    )
  All types appearing in instance declarations must be of the form T a_1 .. a_n, where each type a_i is of the same form.
in type class instance MonadHttp.MonadMine (Aff
                                              ( ajax :: AJAX
                                              | e
                                              )
                                           )

To work around this, one must create a newtype to wrap the type being instanced, and then create the instance for that newtype instead. (Example)

Is there a reason why the PureScript compiler rejects using rows in the instance declaration? It seems like on face value that this should work.

@paf31
Copy link
Contributor

paf31 commented Jun 16, 2016

Rows are not allowed in instance heads, although there may be a workaround once we get ~ constraints:

instance monadMine :: (e ~ (ajax :: AJAX)) => MonadMine (Aff e)

There are existing discussions about this in #1510 and #1822.

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

No branches or pull requests

2 participants