Unbox sum types without fields
In the new I/O manager we use newtyped Int
s instead of an ADT to squeeze out every drop of performance GHC can give us. It's a bit unfortunate that we have to make a choice between performance and safety here. Using an ADT have many benefits. For example, all possible values are grouped together neatly under the data type and the compiler can make sure we check all possible cases in case statements.
Pointer tagging helps quite a bit here, if you have fewer than 4 (or 8) constructors. If you have more you don't get the benefit.
Given a simple sum type like this:
data Color = Red | Green | Blue | Yellow
change its representation to an Int
, allowing it to be unboxed into data types.
Trac metadata
Trac field | Value |
---|---|
Version | 7.0.1 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | johan.tibell@gmail.com |
Operating system | |
Architecture |