Visitar URL original
Introducing `TypeOf` type family by gdeest · Pull Request #72 · tweag/capability · GitHub
Skip to content

Introducing TypeOf type family - #72

Merged
gdeest merged 4 commits into
masterfrom
type-of
May 2, 2019
Merged

gdeest merged 4 commits into
masterfrom
type-of

Conversation

@gdeest

@gdeest gdeest commented May 2, 2019 •

Copy link
Copy Markdown
Contributor

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.

@gdeest
gdeest requested review from aherrmann and aspiwack as code owners May 2, 2019 08:17
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.
Comment thread examples/Reader.hs Outdated
import Test.Common
import Test.Hspec

data Tag = Foo | Bar

Copy link
Copy Markdown
Collaborator

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 Bar

So as not to give the impression that TypeOf needs to be used with a closed kind?

Copy link
Copy Markdown
Contributor Author

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 !

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrkkrp This seems like an accurate statement. Is this a Haskell2010 thing?

@gdeest probably the extension line can be removed, then: that's one fewer lines!

Comment thread 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.

Copy link
Copy Markdown
Collaborator

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.

@gdeest

gdeest commented May 2, 2019

Copy link
Copy Markdown
Contributor Author

PTAL.

Comment thread src/Capability/TypeOf.hs
-- 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

Copy link
Copy Markdown
Collaborator

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 aherrmann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat, thank you!

@gdeest
gdeest merged commit 220abdf into master May 2, 2019
@gdeest
gdeest deleted the type-of branch May 2, 2019 16:37
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.

Associate type to tags

4 participants