public
Created

newtype vs data in haskll

  • Download Gist
newtype laziness
1 2 3 4 5 6 7 8
Prelude> data D = D Int
Prelude> let f (D i) = "ok"
Prelude> f undefined
"*** Exception: Prelude.undefined
Prelude> newtype D = D Int
Prelude> let f (D i) = "ok"
Prelude> f undefined
"ok"

Just ran in to the same issue and got the same result as you ... took forever to figure out what the issue was. Thanks for posting this.

I found this link from this StackOverflow comment.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.