Motivation for refineDefaultAlt

Simon Jakobi simon.jakobi at googlemail.com
Fri May 11 15:17:28 UTC 2018


Hi!

I thought refineDefaultAlt was about scenarios like this:

data D = C0 | C1 | C2

case e of
   DEFAULT -> e0
   C0 -> e1
   C1 -> e1

When we apply combineIdenticalAlts to this expression, it can't
combine the alts for C0 and C1, as we already have a default case.

If we apply refineDefaultAlt first, we get

case e of
  C0 -> e1
  C1 -> e1
  C2 -> e0

and combineIdenticalAlts can turn that into

case e of
  DEFAULT -> e1
  C2 -> e0

But that's just my own interpretation and possibly not the original motivation.

Cheers,
Simon



2018-05-11 17:03 GMT+02:00 Simon Peyton Jones via ghc-devs
<ghc-devs at haskell.org>:
> Because if e contains
>
>             …(case x of Foo p q -> e2)…
>
> as a sub-expression, we’d like to simplify it.
>
>
>
> Sorry that is not documented; please do add that to the comments in the
> source code.
>
>
>
> Simon
>
>
>
> From: ghc-devs <ghc-devs-bounces at haskell.org> On Behalf Of Matthew Pickering
> Sent: 11 May 2018 15:54
> To: GHC developers <ghc-devs at haskell.org>
> Subject: Motivation for refineDefaultAlt
>
>
>
> Hi all,
>
>
>
> Does anyone know the motivation for refineDefaultAlt?
>
> The comment states
>
> - -- | Refine the default alternative to a 'DataAlt', if there is a unique
> way to do so.
>
> OK - so the code transforms something like
>
> case x of { DEFAULT -> e }
> ===>
>
> case x of { Foo a1 a2 a3 -> e }
>
>
> but why is this necessary or desirable?
>
> Perhaps you know Simon (Jakobi)?
>
> Cheers,
>
>
>
> Matt
>
>
>
>
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
>


More information about the ghc-devs mailing list