[Haskell-cafe] Re: Dynamic typing of polymorphic functions

Ben Franksen ben.franksen at online.de
Thu Dec 27 17:30:46 EST 2007


Alfonso Acosta wrote:
> 2) Think of a change in the internal representation of signals which
> made polymorphic processes possible. Polymorphic processes don't have
> to
>     be necessarily definable by the user. They should be happy enough
> with a few polymorphic primitives (mapSnd would be one of them).

I am not sure if this is applicable to your problem, but in GHC you can wrap
polymorphic values in a newtype using higher-rank polymorphism, like in

newtype WrapId = WrapId { unWrapId :: (forall a. a -> a) } deriving Typeable

You can then use

  toDyn . WrapId

to wrap 'id' into a Dynamic and

  unWrapId . flip fromDyn (error "wrong type")

to unwrap it.

Cheers
Ben



More information about the Haskell-Cafe mailing list