[Haskell-cafe] Re: Storing functional values

ajb at spamcop.net ajb at spamcop.net
Mon Feb 2 19:29:30 EST 2004


G'day.

Quoting nickgrey at softhome.net:

> This is the kind of thing I'd like to do, but I can't see how to do it.
> (Not that I'm claiming it's impossible, I'd played with Haskell on and off
> for a couple of years now, but I'm a long way from being an expert.)
>
> class StoreableFunc1 a where
>  store   :: a -> String
>  unstore :: String -> a
>  apply   :: ?? -- What type here??

How about this?

        class StorableThing thing f | thing -> f where
                store :: thing -> String
                unstore :: String -> thing
                retrieve :: thing -> f

Then you can say, for example:

        data IdFunction = IdFunction

        instance StorableThing IdFunction (forall a. a -> a) where
                store _ = "IdFunction"
                unstore _ = IdFunction
                retrieve _ = id

Note that you're still going to have problems with unstoring these
beasts.  How to do this is left as an exercise.  (Clue: Existential
types may help you a lot.)

Cheers,
Andrew Bromage


More information about the Haskell-Cafe mailing list