
Hi, I can't really describe it in the subject. So let me try to do it here. I have two functions
f :: a -> b g :: (a -> b) -> c -> d
and I use them as
gf :: c -> d gf = g f
Now I want to handle exceptions in f and redefine f as in f'
f' :: a -> IO (Either e b)
So my question is how to define gf' now to use f' instead of f?
gf' :: c -> IO (Either e d)
Thanks in advance. Xiao-Yong -- c/* __o/* <\ * (__ */\ <

On Tue, May 12, 2009 at 04:59:36PM -0400, Xiao-Yong Jin wrote:
f :: a -> b g :: (a -> b) -> c -> d
gf :: c -> d gf = g f
Now I want to handle exceptions in f and redefine f as in f'
f' :: a -> IO (Either e b)
So my question is how to define gf' now to use f' instead of f?
gf' :: c -> IO (Either e d)
Use Control.Monad.Error.ErrorT, it's exactly for this. You have to "monadize" g to be able to pass f' as an argument to it. f' :: a -> ErrorT e IO b g' :: Monad m => (a -> m b) -> c -> m d gf' :: c -> ErrorT e IO d gf' = g' f' Here "e" should be some fixed instance of Error. HTH. Lauri

Lauri Alanko
On Tue, May 12, 2009 at 04:59:36PM -0400, Xiao-Yong Jin wrote:
f :: a -> b g :: (a -> b) -> c -> d
gf :: c -> d gf = g f
Now I want to handle exceptions in f and redefine f as in f'
f' :: a -> IO (Either e b)
So my question is how to define gf' now to use f' instead of f?
gf' :: c -> IO (Either e d)
Use Control.Monad.Error.ErrorT, it's exactly for this. You have to "monadize" g to be able to pass f' as an argument to it.
f' :: a -> ErrorT e IO b g' :: Monad m => (a -> m b) -> c -> m d gf' :: c -> ErrorT e IO d gf' = g' f'
So there is no way to do it without "monadize" g to g', is it? Big trouble, sigh. -- c/* __o/* <\ * (__ */\ <

Xiao-Yong Jin schrieb:
Lauri Alanko
writes: On Tue, May 12, 2009 at 04:59:36PM -0400, Xiao-Yong Jin wrote:
f :: a -> b g :: (a -> b) -> c -> d gf :: c -> d gf = g f Now I want to handle exceptions in f and redefine f as in f'
f' :: a -> IO (Either e b) So my question is how to define gf' now to use f' instead of f?
gf' :: c -> IO (Either e d) Use Control.Monad.Error.ErrorT, it's exactly for this. You have to "monadize" g to be able to pass f' as an argument to it.
f' :: a -> ErrorT e IO b g' :: Monad m => (a -> m b) -> c -> m d gf' :: c -> ErrorT e IO d gf' = g' f'
So there is no way to do it without "monadize" g to g', is it? Big trouble, sigh.
Sure, but I'm afraid that gets more complicated. Btw. you can also use ExceptionalT and Exceptional from explicit-exception package, which does not require a constraint on the exception type.
participants (3)
-
Henning Thielemann
-
Lauri Alanko
-
Xiao-Yong Jin