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

Antoine Latter aslatter at gmail.com
Fri Nov 4 14:26:08 CET 2011


On Fri, Nov 4, 2011 at 7:51 AM, Amy de Buitléir <amy at nualeargais.ie> wrote:
> Antoine Latter <aslatter <at> gmail.com> writes:
>
>> A really simple and common way to do this would be using a sum-type:
>
> Here's what I'm trying to accomplish. I want to write a daemon that will cycle
> through the files, load each one in turn, and invoke the doSomething method. I
> would like to be able to allow people to use my daemon with any assortment of new
> types that they create, as long as that type implements the doSomething,
> readThing, and writeThing methods.
>
> I could make the sum-type approach work, but then users would have to modify the
> type. And there might be dozens of different types in use, some provided by me,
> and some provided by the user, so it would get messy. But I might have to go
> with that approach.
>

An executable, once compiled, cannot really learn about new types
without dynamically loading new object code. Which is possible but
often tricky.

You'd have this problem in other languages, too, except Java and .Net
have spent a lot of time working on the dynamic loading of new object
code into a running process (but you would still need to get the
.class file or .dll into a folder where the executable can read it).

Maybe I'm mis-understanding your requirements, though.

Antoine



More information about the Beginners mailing list