[Haskell-beginners] Haskell wants the type, but I only know the class.

Antoine Latter aslatter at gmail.com
Thu Nov 3 20:21:36 CET 2011


On Thu, Nov 3, 2011 at 1:08 PM, Amy de Buitléir <amy at nualeargais.ie> wrote:
> Thank you, David and Antoine.
>
> I was planning to have files containing different types of objects, but where
> all of the types are instances of a particular class. Since the class definition
> ensures that whatever the types are, they implement the methods that I need, I
> hoped to be able to manipulate the files using those methods, without having to
> find out the class programmatically.
>
> Clearly I need to rethink this. I'm looking into existentially quantified data
> constructors now, maybe that will help.
>

You'll still need some way to build the existential data constructor
at run-time - what information will you have at run-time to select the
right instance?

One thing to keep in mind is that GHC erases types during compilation,
so there isn't any sort of run-time operator like 'getTypeByName ::
String -> Type'.

Some projects (acid-state, in particular) build up mappings from
ByteString tags to existential constructor types which can be used to
deserialize binary data. I'd be interested in knowing what other folks
do for this sort of thing.

Antoine

>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



More information about the Beginners mailing list