On 12-12-05 12:48 AM, Jason Dagit wrote:
I thought it was possible to get around this with lazy patterns such
"Wadler's force function" [1]?

(untested code)

force y =
   let Just x = y
   in Just x

lazyDecode :: FromJSON a => ByteString -> Maybe a
lazyDecode = force . decode

This says, the type is Maybe, but the value is always Just. If there will be a parse error, you will get an async imprecise exception, not Nothing, at the later time when you look closer.

This respects the letter, but not the point, of the Maybe type. If you are to do this (I have no moral, I hold nothing against doing this, the async imprecise exception will give you enough grief), you may as well skip the Just wrapping and directly go ByteString -> a.

The point of the Maybe type is to communicate parse errors by a less async, less imprecise way.

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

Reply via email to