[Haskell-cafe] Template Haskell sees into abstract data types

Jonas Almström Duregård jonas.duregard at gmail.com
Wed Jul 28 04:18:26 EDT 2010


Hi,

> I cannot write classes that see into internal structure. For example,
> I cannot write my own (de)serialization without using from/toAscList.

Actually I don't believe you can do this with TH either. TH splices
code into the module where you use it. The generated code is then type
checked in this module. If constructors that are not exported are used
in the generated code, I believe you will get an error.

This could still be an issue because your TH code won't know if the
constructors are exported or not, but i doubt you can actually do
things with TH that you can't do with plain H.

> At least, it looks like I can, I didn't tried, actually.

Neither have I.

/J

On 4 July 2010 01:10, Serguey Zefirov <sergueyz at gmail.com> wrote:
>>> I cannot directly create my own class instances for them because of
>>> that. But I found that I can write Template Haskell code that could do
>>> that - those data types could be reified just fine.
>> Huh?  Sure you can write class instances for them.
>> ,----
>> | instance SizeOf (Map k v) where
>> |   sizeOf = Map.size
>> `----
>
> Those are trivial. They are not interesting.
>
> I cannot write classes that see into internal structure. For example,
> I cannot write my own (de)serialization without using from/toAscList.
>
>>> This is somewhat strange situation.
>>> Was it a design decision?
>> The reason that they are exported abstractly is so that you don't see
>> the internals of the data structure, because 1) you don't need to, and
>> 2) to stop you from doing anything stupid with them.
>
> I was talking about successful reification of abstract data types.
>
> That way I can do anything stupid with them.
>
> At least, it looks like I can, I didn't tried, actually.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list