On Mon, Oct 6, 2008 at 2:19 PM, Arnar Birgisson <[EMAIL PROTECTED]> 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
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to