[Haskell-cafe] Data & newtype differences. Today: strictness

Yves Parès yves.pares at gmail.com
Sun Jan 22 15:18:41 CET 2012


Thanks, that's clearer to me now.

It confirmed my thoughts:
> Matching the pattern con pat against a value, where con is a constructor
defined by newtype, depends on the value:
> - If the value is of the form con v, then pat is matched against v.
> - If the value is ⊥, then pat is matched against ⊥.

Put shorter:
newtype TestN = TestN Int

TestN x = undefined

Then x = undefined.

Which means you cannot make a boxed type out of un unboxed one using
newtype. That makes sense.

2012/1/22 Roman Cheplyaka <roma at ro-che.info>

> * Yves Parès <yves.pares at gmail.com> [2012-01-22 11:32:30+0100]
> > These make me think that pattern matching against a newtype is always
> lazy
> > (irrefutable). Am I right?
>
> Yes.
>
> > Is there some litterature expliciting in a less empiric way than I did
> the
> > differences like this between data and newtype? I've never come against
> > such documentation through all my learning of Haskell, yet I think it's
> an
> > important point.
>
> See the Haskell report, section 3.17.2 "Informal Semantics of Pattern
> Matching" [1].
>
> In particular, this paragraph:
>
>    The irrefutable patterns are as follows: a variable, a wildcard, N
>    apat where N is a constructor defined by newtype and apat is
>    irrefutable (see Section 4.2.3), var at apat where apat is irrefutable,
>    or of the form ~apat (whether or not apat is irrefutable). All other
>    patterns are refutable.
>
> [1]:
> http://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-600003.17.2
>
> --
> Roman I. Cheplyaka :: http://ro-che.info/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120122/f96cd914/attachment.htm>


More information about the Haskell-Cafe mailing list