[Haskell-cafe] Re: how would this be done? type
classes?existential types?
Brian Hulley
brianh at metamilk.com
Fri Mar 17 11:57:30 EST 2006
Ben Rudiak-Gould wrote:
> Matthias Fischmann wrote:
>> now i want to create a list of a type similar to
>>
>> [r1, r2, r3] :: (Resource a) => [a]
>>
>> but with r1 being pizza, r2 being crude oil, and so on.
>
> The type you actually want here is [exists a. (Resource a) && a], but
> no Haskell implementation supports that.
Is there a reason for using && instead of
[exists a. Resource a=>a]
?
Also, am I right in thinking that the reason why no implementation supports
this is as follows:
a) A value 'v' of type 'exists a. Resource a=>a 'would have to be internally
represented as something like (dictResource_t, value_t)
and
b) Given such a value, there is no syntactic way to distinguish the pair
from the value_t stored inside it, unlike the use of 'forall' where the
syntax for the constructor conveniently "represents" any dictionaries that
have been glued onto the value (ie pattern matching against R x gives us
back the dictionaries "R" and the plain value x)?
Hope I'm not making this more confusing but I'm still trying to get my head
around all these invisible happenings regarding dictionaries so I can
visualise what's happening in terms of bytes and pointers in the runtime....
Thanks, Brian.
More information about the Haskell-Cafe
mailing list