
Ok, but it sounds like you need to know the list of possible types in advance. Is it possible to have a lib take a filepath and type name as an arbitrary string, and read the instance in? The context here is that I'm writing an App Server (tentative name: HAppS) that given an instance of: class (Eq state, Read state,Show state ,Eq request, Read request, Show request) => App state request response where startState::state execRequest::state-> CallBack state -> Chan a -> ReqContext request -> Result state response takes an arbitrary state, does write-ahead logging of any requests that change that state, and periodically saves the state to disk. If the computer dies or is shutdown for any reason, the last saved state is read-back from disk and the log is replayed until state is current, at which point, new requests may be processed. (Think Prevayler, but with side-effects and state saving handled properly -- thanks to Haskell's type system!) To use this lib, you do: main = (serveApp requestProducer filepaths)::YourAppInstance serveApp then attempts to read in the state from the filepaths and calls startState otherwise. The explicit type here coerces serveApp to read or startState the proper type (serveApp returns the state eventually). The problem is that the type of requestProducer is sort of complex (simplifying): type ReqProd=(((Respond, request) -> IO ()) -> IO t) type Respond response = response -> IO () It is a function that takes a function that writes (respond,request) pairs to a channel and when run, calls that function periodically to interact with state. I find this is a bit hard to understand (and I just wrote the code!). I'd really like serveApp to return the writeChannel function and then have the client code call it. Then calling serveApp would look like: main = do queueReuest <- serveApp filePaths "YourAppInstance" Even better, I'd love to have the same app be able to handle multiple request types (via existential types), but right now, thats not possible because I need to be able to (read) them. -Alex- _________________________________________________________________ S. Alexander Jacobson mailto:me@alexjacobson.com tel:917-770-6565 http://alexjacobson.com On Mon, 26 Apr 2004, Chung-chieh Shan wrote:
S. Alexander Jacobson
wrote in article in gmane.comp.lang.haskell.cafe: Is is possible to read/show an existentially typed list?
Would it be possible if, instead of using read/show, I defined some variant that relies on the typeof/typeable infrastructure? Is there a way to read in a typename for use in coercing a read?
Dylan Thurston and I encountered this problem a while ago. Show is easy: just use a type like "exists a. Show a => ...". Read is hard, because one needs to get the Read dictionary from somewhere, and the dynamic typing facility in Haskell does not include type-class constraint reduction at runtime. The best solution we came up with was to replace the existentially typed list with a list of string-string pairs, where the first string names the type and the second string names the value. The call to "read" is only done at lookup time, not at file-reading time.
-- Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig Be it declared and enacted by this present Parliament / That the People of England / are / a Commonwealth and free State / without any King or House of Lords. -- An Act declaring England to be a Commonwealth 1649-05-19 | 355 years | 2004-05-19 http://tinyurl.com/2dqnh
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe