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

2012-01-24 Thread Ketil Malde
Yves Parès yves.pa...@gmail.com writes: I had for long thought that data and newtype were equivalent, but then I spotted some differences when it comes to strictness. data Test = Test Int newtype TestN = TestN Int Interesting. I'd thought that data Test = Test !Int and newtype Test

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

2012-01-24 Thread Erik Hesselink
An interesting use case for this is that while data Void = Void Void has infinitely many values (undefined, Void undefined, Void (Void undefined) etc), the newtype version newtype Void = Void Void has only one, bottom. This is a way to define the empty datatype without extensions. Erik

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

2012-01-22 Thread Yves Parès
Hello, I had for long thought that data and newtype were equivalent, but then I spotted some differences when it comes to strictness. Those can be summed up as: data Test = Test Int newtype TestN = TestN Int pm (Test _) = 12 -- Strict (pm undefined = undefined) pm2 t = t `seq` 12 -- Strict

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

2012-01-22 Thread Roman Cheplyaka
* Yves Parès yves.pa...@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?

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

2012-01-22 Thread Yitzchak Gale
Yves Parès wrote: 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. Roman Cheplyaka wrote: See the

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

2012-01-22 Thread Yves Parès
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 ⊥.

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

2012-01-22 Thread Yves Parès
Big sum up of everything: If TestN is a newtype constructor, then 'TestN undefined' and 'undefined' are exactly the same thing. 2012/1/22 Yitzchak Gale g...@sefer.org Yves Parès wrote: Is there some litterature expliciting in a less empiric way than I did the differences like this

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

2012-01-22 Thread Roman Cheplyaka
* Yves Parès yves.pa...@gmail.com [2012-01-22 15:23:51+0100] Big sum up of everything: If TestN is a newtype constructor, then 'TestN undefined' and 'undefined' are exactly the same thing. To be precise, the former is a type-restricted version of the latter. -- Roman I. Cheplyaka ::