[Haskell-cafe] Static computation/inlining
steve at fenestra.com
Mon Oct 11 09:54:04 EDT 2010
On Sun, 10 Oct 2010 18:51:59 -0700, Alexander Solla <ajs at 2piix.com>
>Although the list isn't huge, I would still rather get rid of the
>O(2*n) operation of turning it into maps at run-time.
I usually handle this as follows:
1) I create my data file in some human-friendly format (such as your
list of tuples), so that I can easily edit it later, as required.
2) I write a program, a sort of preprocessor, that (a) loads the data
from the human-friendly format into a processing-friendly structure, and
then (b) serializes that structure into a file that's efficient to load
at run time. (So, for example, lookups from the name of a country to its
ISO codes can be handled via a Patricia structure; a Patricia structure
is tedious to construct, but once constructed, is easy to serialize and
3) The file containing the serialized structure is then linked into the
rest of the "real" program as a source unit, where the serialized
structure is represented as a constant (usually a string, but sometimes
an array of numbers, etc.).
If your build environment has a reasonable make-like tool, then the
whole process is pretty automatic; you just modify the human-friendly
file as often as you want, and the preprocessor is invoked
automatically, as needed.
More information about the Haskell-Cafe