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

Arnaud Bailly arnaud.oqube at gmail.com
Wed Jul 14 07:25:41 EDT 2010


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.

Let's say I have something like this:

> data Fun = forall a b . F (a  -> b)
> type Callables = Map String Fun

I would like to be able to write:

> invoke :: Callables -> a -> String -> b
> invoke m d k = case lookup k m of
>  Just (F f) -> f d
>  Nothing   -> error $ "unable to find function for key " ++ k

which of course does not compile nor even make sense. I suspect I need
to have more information in Fun to be able to apply functions
correctly, but don't know where to look at.
I read recently an article about implicit configurations that used
some type wizardry to ensure correct and typesafe use of external data
and sounded pretty cool,
(http://www.cs.rutgers.edu/~ccshan/prepose/prepose.pdf) but I suspect
this is 1) too complex for me an 2) overkill for my problem.

Could someone point me in the right direction ?

Thanks in advance
Arnaud


More information about the Haskell-Cafe mailing list