Re: [Haskell-cafe] propogation of Error

2008-12-05 Thread Daniel GorĂ­n

i would expect to get back the Error from the *first* function in the
sequence of functions in checkHeader (oggHeaderError from the  
oggHeader

function). but instead i always see the Error from the *last* function
in the sequence, OggPacketFlagError from the OggPacketFlag function.  
why
is this? is there any way i can get the desired behavior...i.e. see  
the

Error from the first function in the sequence that fails?



Hi

You are essentially asking why this function:

checkHeader handle = ((oggHeader handle)   
  (oggStreamFlag handle)   
  (oggHeaderFlag handle)   
  (skipBytes handle 20)
  (oggPageSecCount handle) 
  (oggPacketFlag handle))

returns the last error (OggPacketFlagError) instead of the first one.  
Some type annotations might help you see what is going on. So let's  
ask ghci the type of, e.g. oggHeaderFlag


*File.Ogg :t oggHeaderFlag
oggHeaderFlag :: SIO.Handle - IO (Either OggParseErrorType [Char])

oggHeaderFlag takes a handle, and computes either an error or a  
string. But since you are using , the computed value is not passed  
to the next function in the pipe! There is no way checkHeader can stop  
early simply because it is ignoring the intermediate results altogether.


Since you are importing Control.Monad.Error, I believe you would  
probably want oggHeaderFlag et al to have type:


SIO.Handle - ErrorT OggParseErrorType IO [Char]

This will propagate errors correctly.

You can see a version of your code using ErrorT here: http://hpaste.org/12705#a1

Daniel
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] propogation of Error

2008-12-04 Thread brad clawsie
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

hi. i have a partial library for parsing ogg files here:

http://hpaste.org/12705

i have a question about an aspect of the code. in the function 

checkHeader

there are a sequence of functions to check various elements in the
header of a ogg file. if i test this function against a file that
*isn't* an ogg file, i.e.

badFile = /home/user/.bashrc :: String
main = parseOgg badFile = (\x - print x)

i would expect to get back the Error from the *first* function in the
sequence of functions in checkHeader (oggHeaderError from the oggHeader
function). but instead i always see the Error from the *last* function
in the sequence, OggPacketFlagError from the OggPacketFlag function. why
is this? is there any way i can get the desired behavior...i.e. see the
Error from the first function in the sequence that fails?

thanks
brad
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkk4tQYACgkQxRg3RkRK91PD9gCePloWFIvE9WjcfApxR2RmnHQ0
pUgAn0WAzRQR/y2yE8yeYP1s7eKHyKDh
=EcOM
-END PGP SIGNATURE-
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe