Type families: module export of instance data constructor
ben.horsfall at gmail.com
Mon Dec 22 01:05:35 EST 2008
I'm afraid I'd got into a muddle, and all of this can be ignored.
In general, top-level and associated type instances get the same
syntactic treatment in module exports, and the problem I had in the
first place was due to another mistake.
On Mon, Dec 22, 2008 at 4:26 PM, Ben Horsfall <ben.horsfall at gmail.com> wrote:
> Hi Wolfgang,
> On Mon, Dec 22, 2008 at 12:23 PM, Wolfgang Jeltsch
> <g9ks157k at acme.softbase.org> wrote:
>> Am Montag, 15. Dezember 2008 02:17 schrieb Ben Horsfall:
>>> I have a type family
>>> class Lang term where
>>> data Token term :: *
>>> instance Lang Term where
>>> newtype Token Term = T String
>>> I can't work out how to export the type constructor T from the module,
>>> unless I make no explict exports from the module at all.
>> Hello Ben,
>> Lang (type Token)
>> in the export list.
>> Best wishes,
> That exports just the name of the associated type from the type class,
> as far as I can see, and syntax like "Lang (type Token (..))" is not
> allowed. That would improperly mix the classes and instances, for one
> thing. But perhaps something similar ought to be permited for
> associated type instances, as in my example. Something like:
> module Term (Term (Token Term (T)))
> is what I'd have in mind.
> In the meantime, I can step around the issue by making Token a
> top-level type familiy alongside the Lang class:
> data family Token term :: *
> with instance:
> newtype instance Token Term = T String
> alongside the instance Lang Term, allowing me to make the module
> exports I wanted in the usual style:
> module Term (Term (..), Token (T))
> But this is a bit curious. The module might have contained more than
> one instance of Token, and this syntax mentions the name of the type
> family and a constructor for an instance of it, but not the type
> instance Token Term itself (although a constructor will always
> uniquely determine a type instance).
> This reminds me to mention that I've had the class and instance
> declarations in separate modules all along. Also, I'm using GHC
More information about the Glasgow-haskell-users