[Haskell-cafe] data/newtype examples

Olaf Klinke olf at aatal-apotheke.de
Fri May 6 22:02:05 UTC 2022

> Dear Cafe -
> I wanted a quick example (for teaching)
> that shows a difference between data and newtype.
> What examples do you use?
> I'm interested both in simple ones,
> and confusing/obfuscated ones.

Perhaps on the obscure side: I like to play with different
implementations of Void. Let the students demonstrate that 

newtype Void = Void Void

contains only one element whereas

data Void = Void Void

contains infinitely many elements that can be distinguished by pattern
matching. Also consider data Void = Void !Void. Is this observably
different from the Void newtype? 
Since you will have to explain lifting, you can also demonstrate that(,) is not the categorical product. 


More information about the Haskell-Cafe mailing list