tweag / capability

Extensional capabilities and deriving combinators
BSD 3-Clause "New" or "Revised" License
214 stars 9 forks source link

Associate type to tags #65

Closed aspiwack closed 5 years ago

aspiwack commented 5 years ago

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 :slightly_frowning_face: .

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 commented 5 years ago

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 commented 5 years ago

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