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

Support good type inference with unique parametrized effects #268

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

arybczak
Copy link
Member

@arybczak arybczak commented Nov 4, 2024

I'm very much dissatisfied with the type inference story for parametrized effects.

It's either thousands of type applications or effectful-plugin and I don't particularly like the unnecessary verbosity that comes with the former and the fact that the latter is, well, a GHC plugin and GHC plugins have bugs and usually need to be adjusted for every new GHC version.

Considering the fact that if you use an effect with parameters, then in the vast majority of cases there will be only one instance of it you're using at a time, I remembered re-xyr/cleff#23 and managed to package the idea into a nice-looking interface, so now for chosen effects you can do this:

data Test1 a :: Effect where
  Test1 :: Test1 a m a
makeUniqueEffect ''Test1

data Test2 a b :: Effect where
  Test2 :: Test2 a b m (a, b)
  AmbTest :: Test2 a b m ()
makeUniqueEffect ''Test2

test :: (Num n, IsString s, Test1 n <:> es, Test2 s Char <:> es) => Eff es ()
test = do
  _ <- test1
  _ <- test2
  ambTest

(or write helper functions by hand as usual, just using <:> instead of :>) and it compiles without ambiguity errors.

This PR provides helpers for determining all type parameters up to 5, but one can write a local helper class for any combination.

Thoughts about naming? I think TheN helpers are fine (I thought about UniqueN, but I like TheN better). Not quite sure about <:>, though I couldn't come up with anything better.

TODO:

  • Better naming?
  • Documentation.
  • Helper functions for relevant built-in effects (both static and dynamic).

@arybczak arybczak marked this pull request as draft November 19, 2024 09:12
@mmhat
Copy link
Contributor

mmhat commented Dec 10, 2024

I think that would be a fine addition to the library!
One comment about the naming: When I read <:> it makes me think that that operator is symmetric - I think it's to close to <>.
I propose !:>, :!> or !> (preference on the first): While not quite related to Haskell the exclamation mark reminds me of uniqueness quantification as opposed to existential quantification used in some logics.

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.

2 participants