[Haskell-cafe] evaluating CAFs at compile time

Evan Laforge qdunkan at gmail.com
Mon Jan 27 02:14:51 UTC 2014


On Sat, Jan 18, 2014 at 6:57 PM, Carter Schonwald
<carter.schonwald at gmail.com> wrote:
> Point being, I think your pointing to an idea other people are (also)
> interested in exploring for ghc, and that there's some interesting
> subltelties to it.

I was actually kind of hoping someone would point out some of those
subtleties.  I figure there must be some since I don't know of any
compiler other than the common lisp ones that implements something
like this.

Another thing that it could be useful for is that when declaring data
it's sometimes convenient to declare data structures separately and
then stitch them together, e.g.

xs = makeXs [("name1", a), ("name2", b), ...] -- makeXs uses list
order to infer things
ys = makeYs [('x', ..., "name2"), ('y', ..., "name1")] -- same for makeYs
things = do
    (c, ..., name) <- ys
    let x = fromMaybe (error "ack") $ lookup name xs
    return $ Thing name c x ...

Not only would compile time evaluation eliminate some startup
overhead, it could enforce at compile time that the names match up,
along with other invariants in literal data, such as uniqueness, or
that your keymap doesn't have any collisions, or whatever.


More information about the Haskell-Cafe mailing list