On Tue, Mar 24, 2009 at 3:28 PM, Luke Palmer <lrpal...@gmail.com> wrote:
> On Tue, Mar 24, 2009 at 3:14 PM, Xiao-Yong Jin <xj2...@columbia.edu>wrote: > >> Jake McArthur <j...@pikewerks.com> writes: >> >> > Xiao-Yong Jin wrote: >> > | The problem is that there will be many functions using such >> > | a function to invert a matrix, making this inversion >> > | function return Either/Maybe or packing it in a monad is >> > | just a big headache. >> > >> > I disagree. If you try to take the inverse of a noninvertable matrix, >> > this is an *error* in your code. Catching an error you created in pure >> > code and patching it with chewing gum it is just a hack. A monadic >> > approach (I'm putting Either/Maybe under the same umbrella for brevity) >> > is the only solution that makes any sense to me, and I don't think it's >> > ugly as you are making it out to be. >> > >> >> Then, why is 'div' not of type 'a -> a -> ArithExceptionMonad a' ? >> Why does it throws this /ugly/ /error/ when it is applied to >> 0? Why is it not using some beautiful >> 'ArithExceptinoMonad'? Is 'Control.Exception' just pure >> /ugly/ and doesn't make any sense? > > > It's a proof obligation, like using unsafePerformIO. It is "okay" to use > unsafePerformIO when it exhibits purely functional semantics, but it's > possible to use it incorrectly, and there is no ImpureSemanticsException. > If you are being rigorous, you simply have to prove that the denominator > will not be zero, rather than relying on it to be caught at runtime. You > can move the check to runtime easily: > > safeDiv x 0 = Nothing > safeDiv x y = Just (x `div` y) > > Going the other way, from a runtime check to an obligation, is impossible. > (well, except for div x y = fromJust (safeDiv x y).. but the runtime check is still there in terms of operation)
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe