[Haskell] Better Exception Handling
Jules Bean
jules at jellybean.co.uk
Thu Nov 25 14:34:52 EST 2004
On 25 Nov 2004, at 19:24, Tomasz Zielonka wrote:
> On Thu, Nov 25, 2004 at 07:52:43PM +0100, Lennart Augustsson wrote:
>> As I'm sure you have gathered from all the answers you can't have the
>> latter and keep Haskell pure. But there is an interesting alternative
>> (at least theoretically). You could have a function like
>>
>> mkCatchJust :: IO ((Exception -> Maybe b) -> (c -> a) -> c -> (b ->
>> a) -> a)
>
> How is that different from this?
>
> mkReadFile :: IO (FilePath -> String)
>
> This is wrong. Even if I get a function as a result of an IO
> computation, I
> expect that function to be pure.
Well, you can presumably give it a semantics which is pure. Whether it
makes good sense is another question. The semantics is 'it creates a
function which, when invoked, will return the contents of the file at
some fixed (undefined) time'.
By the same token, you can just stick the function strangeReadFile ::
FilePath -> String into the language. As long as it is memoized, always
returning the same value, it doesn't break beta-reduction. I call it
'strange' because the time that the file is actually read is not
guaranteed, so if you read more than one file in your program, you have
no guarantee that you are reading a constant total state that actually
existed at any point in time. (Before you think this sounds unbearably
horrible, there is at least one commercially sold RDBMS which has this
semantics on its select statements ;P)
Jules
More information about the Haskell
mailing list