-
Notifications
You must be signed in to change notification settings - Fork 9
Introducing TypeOf type family
#72
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
Conversation
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.
examples/Reader.hs
Outdated
| import Test.Common | ||
| import Test.Hspec | ||
|
|
||
| data Tag = Foo | Bar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than using -XDataKind, how about simply defining
data Foo
data BarSo as not to give the impression that TypeOf needs to be used with a closed kind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. -XEmptyDataDecls it is, then !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary in recent versions of GHC, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Capability/TypeOf.hs
Outdated
| -- the type associated to a tag. | ||
| -- | ||
| -- It is poly-kinded, which allows users to define their own type of tags, and | ||
| -- not have to declare orphan type family instances. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a point missing from this comment is that it is not recommended to define TypeOf with symbols. The reason is that it is not compositional and has a high likelihood to interfere with other libraries' instances of TypeOf. That is: symbols all belong to the same global namespace (which is partly why instances with symbols are considered orphans).
It think it needs to be made clear.
There also needs to be an example with tags made in *.
We could get away with TypeOf being defined only on *. But it's a nice plus that we can define it on any tag.
|
PTAL. |
| -- Standard haskell types can also be used as tags by specifying the '*' kind | ||
| -- when defining the type family instance. | ||
| -- | ||
| -- Defining 'TypeOf' instances for 'GHC.TypeLits.Symbol's (typelevel string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check that haddock renders the second link correctly.
aherrmann
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat, thank you!
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 this feature.