Skip to content

Conversation

@gdeest
Copy link
Contributor

@gdeest gdeest commented 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 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.
import Test.Common
import Test.Hspec

data Tag = Foo | Bar
Copy link
Member

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
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
Member

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
Member

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!

-- 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
Member

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
Copy link
Contributor Author

gdeest commented May 2, 2019

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
Copy link
Member

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.

Copy link
Member

@aherrmann aherrmann left a comment

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

5 participants