Why is there "data" and "newtype" in Haskell?

Posted by martingw on Stack Overflow See other posts from Stack Overflow or by martingw
Published on 2010-04-15T22:03:11Z Indexed on 2010/04/15 23:13 UTC
Read the original article Hit count: 155

Filed under:
|

To me it seems that a newtype definition is just a data definition that obeys some restrictions (only one constructor and such), and that due to these restrictions the runtime system can handle newtypes more efficiently. Ok, and the handling of pattern matching for undefined values is slightly different. But suppose Haskell would only knew data definitions, no newtypes: Couldn't the compiler find out for himself whether a given data definition obeys these restrictions, and automatically treat it more efficiently? I'm sure I'm missing out on something, these Haskell designers are so clever, there must be some deeper reason for this...

© Stack Overflow or respective owner

Related posts about haskell

Related posts about language-design