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

Associate type to tags #65

Closed
aspiwack opened this issue Dec 6, 2018 · 2 comments · Fixed by #72
Closed

Associate type to tags #65

aspiwack opened this issue Dec 6, 2018 · 2 comments · Fixed by #72

Comments

@aspiwack
Copy link
Member

aspiwack commented Dec 6, 2018

Currently, we have to write

HasState "mytag" MyType m =>

This is all fine for library, and basically necessary for deriving-via combinators. But it's a bit annoying in an application. Where typically, a tag correspond to a given type. e.g. HasReader "config" would always be followed by the same configuration type. Throughout the entire application. Meh 🙁 .

We should do something about this.

At this point my idea looks a bit as follows. We define a type family

type familly TypeOf (s :: Symbol) :: *

(with no instance in the library)

And type synonyms like

type HasState' s = HasState s (TypeOf a)

This way, you could define application-wide tag-to-type associations and have shorthands for them.

Or maybe, in order to avoid the lack of composability that symbol have, we could do

type family TypeOf (s :: *) :: *

That way they can be defined without orphan instances.

Thoughts?

@aherrmann
Copy link
Member

Tags are poly-kinded. So, in such cases, we could use the type as a tag as well.

For example:

type HasState' s = HasState s s

data Config = ...

foo :: HasState' Config m => m ()
foo = ...

@aspiwack
Copy link
Member Author

aspiwack commented Dec 7, 2018

Uh. Please no! Not doing that is sort of the entire point of tags to begin with.

gdeest pushed a commit that referenced this issue May 2, 2019
Fixes #65.

Introduces a poly-kinded type family to allow users to associate tags to type, and corresponding type synonyms for all capabilities to shorten constraint declarations.
gdeest pushed a commit that referenced this issue May 2, 2019
Fixes #65.

Introduces a poly-kinded type family to allow users to associate tags to type, and corresponding type synonyms for all capabilities to shorten constraint declarations.

Also changes the Reader example to make use of that feature.
@gdeest gdeest closed this as completed in #72 May 2, 2019
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 a pull request may close this issue.

2 participants