Worker/Wrapper for sum return
GHC version 8.2 introduces Unboxed Sum types. It would be great if the worker/wrapper transformation could make use of this new functionality.
For clarification I would expect a function like this:
maybeEven :: Int -> Maybe Int
maybeEven n = case even n of
True -> Just n
False -> Nothing
to be transformed into (the core equivalent) of
maybeEven :: Int -> Maybe Int
MaybeEven (I# n#) = case workerMaybeEven n# of
(# | x #) -> Just x
(# (# #) | #) -> Nothing
workerMaybeEven :: Int# -> (# (# #) | Int #)
{-# NOINLINE workerMaybeEven #-}
workerMaybeEven n# = case even (I# n#) of
True -> (# | I# n# #)
False -> (# (# #) | #)
Currently the core output for the maybeEven worker is:
Main.$wmaybeEven :: Int# -> Maybe Int
Main.$wmaybeEven
= \ (ww_s4WH :: Int#) ->
case remInt# ww_s4WH 2# of {
__DEFAULT -> GHC.Base.Nothing @ Int;
0# -> GHC.Base.Just @ Int (GHC.Types.I# ww_s4WH)
}
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.2.1 |
| Type | FeatureRequest |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |