[Haskell-cafe] Re: type versus data declarations

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

Hi Alfonso!

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

> On 6/8/07, Emilio Jesús Gallego Arias <egallego at babel.ls.fi.upm.es> wrote:
> Yep, you're right. a is alredy universally quantified in the RHS. This
> is probably what you're looking for:
> type FSet a = forall a. Show a => (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.
> hold?


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

> up :: Double -> Double
> up x = x + 1

> m :: FSet
> m = up

This doesn't work.

I really want to use some functions that are not general enough. If the
function cannot touch it's value (as it's the case with forall), then
the function is almost useless, unless you'd like to do some type level
programming. I'd like to have different functions for the same type, so
I cannot pack it into a type class.

>> 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.
> I know, it can be a pain to have to carry the type class constraints
> everywhere. Maybe the type redefinition using existentials I wrote
> above can help. Otherwise I guess you'll have to cope with writting
> the constraint in every function signature.

Yeah, in general Haskell types don't carry constraints, however, I don't
see the reason that this doesn't work when using type level macros, as

> type F a = C a => a

should just be a macro and substitute.



More information about the Haskell-Cafe mailing list