|
RE: Imperative Object Destruction: msg#00042lang.haskell.general
At 2000-11-13 01:27, Chris Angus wrote: >why not create an abstract datatype > >OpenFile a which is a monad > >data OpenFile a = OpenFile (Maybe FileHandle -> IO a) > >and create you operations in terms of this > >openFile :: String -> OpenFile () >count :: OpenFile Int >read :: Int -> OpenFile [Byte] > >then you could habe a run function > >runOF :: OpenFile a -> IO a > >which ran whatever you wanted for the file and ensured tahthe file was >closed correctly afterwards. This is a slight generalisation of my scheme, from which withFile :: OpenFile a -> String -> IO a withFile operation name = runOF (openFile name >> operation) >How we would do this with 2 files however I'm not so sure. Looks like you can't. This might work, however: read :: (Int,Int) -> OpenFile IO [Byte] write :: (Int,[Byte]) -> OpenFile IO () withFile :: OpenFile a -> String -> a copyFile :: OpenFile OpenFile IO () withFile (withFile copyFile "dest") "source" ...but I'm not sure how to write copyFile. -- Ashley Yakeley, Seattle WA |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Imperative Object Destruction: 00042, Ashley Yakeley |
|---|---|
| Next by Date: | Re: Imperative Object Destruction: 00042, Hannah Schroeter |
| Previous by Thread: | Re: Imperative Object Destructioni: 00042, Hannah Schroeter |
| Next by Thread: | Re: Imperative Object Destruction: 00042, Ashley Yakeley |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |