type aliases and Id

Ian Lynagh igloo at earth.li
Mon Mar 19 11:35:40 EDT 2007

Hi all,

Suppose I have a datatype:

    data Foo a = Foo {
                     int :: a Int,
                     char :: a Char

where I start off with (Foo Nothing Nothing) :: Foo Maybe, gradually
accumulate values until I have (Foo (Just 5) (Just 'c')), and then I
want to remove the Maybe type so I can lose all the now-redundant Just

Well, suppose in actual fact I prefer the name "CanBe" to Maybe.

Then for the first part I want

    type CanBe a = Maybe a

    foo :: Foo CanBe
    foo = ...

but of course this fails because CanBe is a non-fully-applied type
synonym in "foo :: Foo CanBe", and I can fix this by eta-reducing thus:

    type CanBe = Maybe

    foo :: Foo CanBe
    foo = ...

Now for the second part I want

    type Id a = a

    foo' :: Foo Id
    foo' = ...

but again Id is not fully applied. However, this time I cannot
eta-reduce it! "type Id =" is a parse error, as is "type Id".

I'd really like to be able to define an eta-reduced Id; I see two

* Allow "type Id =" (I prefer this to "type Id" as I think we are more
  likely to want to use the latter syntax for something else later on).

* Implementations should eta-reduce all type synonyms as much as
  possible, e.g.
      type T a b c d = X a b Int c d
  is equivalent to
      type T a b     = X a b Int
      type Id a = a
  is equivalent to a type that cannot be expressed directly.

Any opinions?


More information about the Haskell-prime mailing list