[Haskell-cafe] Data & newtype differences. Today: strictness
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 ⊥.
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
> > (irrefutable). Am I right?
> > Is there some litterature expliciting in a less empiric way than I did
> > 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
> > important point.
> See the Haskell report, section 3.17.2 "Informal Semantics of Pattern
> Matching" .
> 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.
> Roman I. Cheplyaka :: http://ro-che.info/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe