-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong semantic of newtype #351
Comments
Related to #293. |
You are right, but there is one reason for doing it this way, even if this might be different in Haskell. And this is that
looks exactly like
The behavior of the Frege compiler is so that just by looking at that line you'll know that the argument is strict. You don't have to know that All you need to know is: Ohh, this pattern deconstructs something, hence it will be strict. |
I still think pattern match on constructor of newtype designed as strict will not be reasonable. It always will be wired in some case. Consider this:
Now does it feel the pattern match should always don't fail? The pattern should only strict on constructor right? We don't care about what value it contains. But we still get ⊥ if we deal pattern match as strict. The best way to think about newtype imo is: It just synonym of the type. We use constructor, pattern match every time when we want to convert between them. The convert should be prefect. So we are not really create new data type or pattern match on data type. We just want to change the name of type. |
Consider following code:
What is the result of this program? Since newtype is perfect isomorphism. Code above should identical to:
Which should display "()" in console. But program instead simply crashed. Because definition of
foo
generated codefinal public static short foo(final String/*<Character>*/ arg$1)
. Which is not lazy. And compiler gererates codefoo(PreludeBase.<String/*<Character>*/>undefined().call())
. So we got ⊥.The text was updated successfully, but these errors were encountered: