
#14826: Flatten data types extending other data types in STG -------------------------------------+------------------------------------- Reporter: nomeata | Owner: (none) Type: feature request | Status: new Priority: low | Milestone: Component: Compiler | Version: 8.5 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nomeata):
Note that I am NOT re-using the data constructor for Foo (which would be tricky and confusing).
Why not? In fact, with your desguaring, and #13861, we’d get that: {{{ data Result = Ok_A Int | OK_B Bool | OK_C C | NotOK Error f r = join j x = wimwam x True x in case r as b of OK_A n -> jump j b OK_B b -> jump j b OK_C -> jump j b NOtOK _ -> 0 }}}
I wonder if we could leverage pattern synonyms rather than have more built-in stuff.
Yes, your encoding is all doable with pattern synonyms already: {{{ data Foo = A Int | B Bool | C -- we want: data Result = Ok !Foo | NotOK Error data Result = Ok_A Int | OK_B Bool | OK_C | NotOK Error pattern Ok :: Foo -> Result pattern Ok f <- ((\case Ok_A i -> Just (A i); OK_B b -> Just (B b); OK_C -> Just C; _ -> Nothing) -> Just f) where Ok = \case A i -> Ok_A i; B b -> OK_B b; C -> OK_C }}} or, if people feel bold (and until #13861 does this automatically) {{{ pattern Ok :: Foo -> Result pattern Ok f <- ((\case NotOK _ -> Nothing; foo -> Just (unsafeCoerce foo)) -> Just f) where Ok = unsafeCoerce }}} So since this is somewhat nicely possible, it makes sense for people to play around with either of these encodings using pattern synonyms, and let us know if they notice any gains. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14826#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler