[Haskell-cafe] a really juvenile question .. hehehehe ;^)

Ryan Ingram ryani.spam at gmail.com
Mon Oct 6 10:10:36 EDT 2008

On Mon, Oct 6, 2008 at 2:19 PM, Arnar Birgisson <arnarbi at gmail.com> wrote:
> And this requirement is there why? Is it specifically put in so that
> one is able to create this overhead-less implementation?
> Given:
> data A = A Int
> newtype B = B Int
> ta (A x) = True
> tb (B x) = True
> This happens (not surprisingly given your above comments):
> *Main GOA> :load test.hs
> [1 of 1] Compiling Main             ( test.hs, interpreted )
> Ok, modules loaded: Main.
> *Main GOA> ta undefined
> *** Exception: Prelude.undefined
> *Main GOA> tb undefined
> True
> Why is the x evaluated in ta?

x isn't evaluated.  "undefined" is evaluated to see if it matches the
constructor "A".  But we don't even get to check, because undefined
throws an exception during its evaluation.

In the "tb" case, (B x) always matches because B is a newtype.  x gets
bound to undefined, but never evaluated.

  -- ryan

More information about the Haskell-Cafe mailing list