[Haskell-cafe] Re: type versus data declarations

Emilio Jesús Gallego Arias egallego at babel.ls.fi.upm.es
Fri Jun 8 09:30:25 EDT 2007

Hi Alfonso!

"Alfonso Acosta" <alfonso.acosta at gmail.com> writes:

>> > type FSet a = Show a => (a -> Double)
> type only works for redefinitions (i.e. adding the |Show a| constraint
> makes FSet a different type to (a -> Double)).

Yes, I know.

What I mean, if type is a type macro, why cannot it expand type
constraints too?

Quoting the GHC manual
> > Liberalised type synonyms
> Type synonyms are like macros at the type level, and GHC does validity
> checking on types only after expanding type synonyms.

Seemed to me like a syntactical restriction, however that parses OK, but
the typer complains.

I guess this is due to types like

> type A a = Show a => a
> type B a = Show a => a

so if you do

> f :: A a -> B b
it should get translated to
> f :: (Show a => a) -> (Show b => b)

Which is not valid. I wonder if regrouping all the contexts in the left
side should work:

> f :: (Show a, Show b) => a -> b

> In addition you seem to be trying to pack a dictionary with the type
> (something you cannot do in Haskell without existentials). This is

Why? My first guess it that there's no way to translate that to system
F, but if we look at 'type' as a macro, it could make sense.

> just a guess, but it seems that a definition using existentials is
> what you're looking for.
> data FSet a = forall a. Show a => FSet (a -> Double)

That would be

> data FSet = forall a. Show a => FSet (a -> Double)

not? The above is like

> data FSet b = forall a. Show a => FSet (a -> Double)

I'm not looking yet for existential types, as then my functions will
have to hold for every a, which turns out to be very inconvenient.

The reason I don't want to use data, which works ok, is because I'd like
to use FSet as a function, but not to write the type constraint in every
function using as it is now.

> type FSet a = a -> Double
> a :: Show a => FSet a
> ...

Thanks for your answer,


pd: Greetings from Angel too :)

More information about the Haskell-Cafe mailing list