File tree Expand file tree Collapse file tree 3 files changed +10
-9
lines changed
message-index/messages/GHC-05380 Expand file tree Collapse file tree 3 files changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ constructors, you should use `data` instead of `newtype`.
10
10
11
11
The reason that you need exactly one constructor is that ` newtype ` constructors
12
12
are removed at runtime.
13
- So during runtime, if you define ` newtype Age = Age Int ` , ` Age ` is the same as ` Int ` .
14
- Only during the compilation phase, will the ` Age ` and ` Int ` types be different.
15
- If we allow multiple constructors for a newtype, there would be no way to distinguish them during execution.
13
+ For example, if you define ` newtype Age = Age Int ` , the bits in memory that represent
14
+ an ` Age ` are identical to those that would represent the ` Int ` in the constructor.
15
+ The ` Age ` and ` Int ` types are distinguished only at compile time.
16
+ If types defined with ` newtype ` could have multiple constructors, there would be no way to distinguish them during execution.
Original file line number Diff line number Diff line change @@ -14,5 +14,5 @@ Main.hs:1:1: error: [GHC-05380]
14
14
```
15
15
## Explanation
16
16
17
- A newtype constructor can only have a single constructor. It is not allowed to have multiple
18
- constructors when defining a newtype.
17
+ A ` newtype ` constructor can only have a single constructor.
18
+ It is not allowed to have multiple constructors when defining a ` newtype ` .
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ Main.hs:1:1: error: [GHC-05380]
14
14
15
15
## Explanation
16
16
17
- A ` newtype ` constructor does need to have a single constructor. It is not allowed to
18
- have a newtype without a constructor. It is allowed to have a ` data ` type without a
19
- constructor, so in order to fix this, you need to come up with a constructor for the newtype
20
- or change the ` newtype ` keyword to a ` data ` keyword.
17
+ A ` newtype ` definition is required to have exactly one constructor, so constructorless ` newtype ` s are not allowed.
18
+ Datatypes defined using ` data ` are allowed to be constructorless,
19
+ so this problem can be fixed either by adding a constructor to the ` newtype `
20
+ or by changing the ` newtype ` keyword to a ` data ` keyword.
You can’t perform that action at this time.
0 commit comments