[Yhc] Yhc.Core Proposal: Split out CoreLit's from CoreExpr,
Add CoreAlt
Neil Mitchell
ndmitchell at gmail.com
Fri Aug 3 13:32:10 EDT 2007
Hi,
Following in roughly the same vein as the libraries submission
process, here is a submission to change Yhc.Core.
Currently we have CoreInt, CoreInteger, CoreFloat, CoreDouble etc, all
as members of CoreExpr. For alternatives in a case expression we have
just any expression as the left hand side. I propose:
data CoreExpr = .... | CoreLit CoreLit
data CoreLit = CoreInt Int | CoreInteger Integer | CoreFloat Float
The benefits of this change are minimal, but I think it cleans things up a bit.
Next we can go from:
CoreCase CoreExpr [(CoreExpr,CoreExpr)]
to:
data CoreAlt = AltCon CoreConName [CoreVarName]
| AltLit CoreLit
| AltDefault
CoreCase CoreExpr [(CoreAlt,CoreExpr)]
The advantages of this are many. Currently when matching "[]", it is
possible to end up with CoreApp (CoreCon "[]") [], or CoreCon "[]",
both of which mean the same thing. Additionally, lots of code looks
like:
let (CoreCon a,b) = fromCoreApp lhs
vs = map fromCoreVar b
The fromCoreVar here would crash if any of b's were not variables,
something which is not guaranteed by the type system.
As a reference point, GHC uses something more similar to what is being
proposed. The original reason for allow any arbitrary expression was
to permit desugaring of pattern matches after converting to Core, but
that doesn't appear possible because of lazy/strict pattern matching,
pattern matching in let/where etc. As such there is no benefit to
arbitrary patterns in these positions.
Any comments or thoughts on these things?
Thanks
Neil
More information about the Yhc
mailing list