[Haskell-beginners] Errors and the compiler

Kim-Ee Yeoh ky3 at atamo.com
Fri Oct 12 04:27:32 CEST 2012

The bigger issue here is one's own reasoning about the code, never mind the
compiler's. Bob Harper writes eloquently on this topic:


As for optimality issues, a naive compiler would wastefully examine the tag
twice in the else clause of:

if isNothing mExp
  then expr
  else f (fromJust mExp)

-- Kim-Ee

On Fri, Oct 12, 2012 at 3:48 AM, Christopher Howard <
christopher.howard at frigidcode.com> wrote:

> Point of curiosity: Does an error in a Haskell program have a negative
> impact on the compilers reasoning about or optimization of the code,
> even if said error is never reached in the control flow? For example,
> both of the following would have the same result:
> code:
> --------
> case mExp of
>   Nothing -> expr
>   Just x -> f x
> -- or...
> if isNothing mExp
>   then expr
>   else f (fromJust mExp)
> --------
> In my naive reasoning, I would think that in the latter case the use of
> fromJust introduces, from the compilers perspective, an additional
> possible outcome (an error being thrown). This presumably would
> complicate the compilers reasoning about the code, unless of course the
> compiler is smart enough to figure out that the error will never be
> reached.
> --
> frigidcode.com
> indicium.us
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121012/a8f10de5/attachment.htm>

More information about the Beginners mailing list