[Haskell-cafe] Applying a value to a function generically

Vo Minh Thu noteed at gmail.com
Wed Jul 14 07:38:12 EDT 2010


2010/7/14 Felipe Lessa <felipe.lessa at gmail.com>:
> On Wed, Jul 14, 2010 at 8:25 AM, Arnaud Bailly <arnaud.oqube at gmail.com> wrote:
>> Hello,
>> I would like to construct a collection of function-like objects on
>> which I could apply some value, in a typesafe and clean way.
>
> You could use Data.Typeable.cast [1]
>
> [1] http://haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/Data-Typeable.html#v%3Acast
> [snip]

Or maybe Data.Dynamic

with type Callables = Map String Dynamic
You can extract the function with fromDynamic in a type-safe way (it
returns a Maybe).
Probalby you might want 'invoke' to return a Maybe too (just like Felipe did).

Cheers,
Thu


More information about the Haskell-Cafe mailing list