[Haskell] Re: Compilation of big, static tables
Malcolm.Wallace at cs.york.ac.uk
Thu Feb 23 09:29:54 EST 2006
> >> What I would really like is a syntax to statically construct an
> >> array, without having to compute it from a list. I'm not sure that
> >> even Template Haskell can help here, since there is no normal form
> >> for it to translate to.
> SM> Happy & Alex use the hack of encoding static arrays as strings and
> SM> using peek to access the data at runtime, FWIW.
> this can be accomplished using TH and ForeignArray constructed from
> string constant ("..."#)
Hmm, that only works if the data being stored in the table is of regular
size? I need variable-length values. Using a two- or three-level
encoding into strings would start to get /really/ unpleasant.
And this is pretty ghc-specific stuff.
Perhaps I should propose a new syntactic construct for the language?
(Although not necessarily in time for haskell-prime.)
literalArray -> « literal_0, literal_1, ... , literal_n »
The type of the literal array would be something like
« » :: Ix i => Array i t
Could the array be used at /any/ index type i? Or would it be a fixed
index type, selected by type signature, inference from the usage
context, or failing either of those, the monomorphism restriction?
In any case, the actual bounds would be calculated by the compiler.
What about the content type t? Should it be a fixed type, or would we
permit overloading? Come to think of it, why should we permit only
literals as content elements? Arrays are lazy, so the contents could be
arbitrary expressions, provided they are all of the same type.
literalArray -> « exp_0, exp_1, ... , exp_n »
Would we allow the « » brackets to be used for pattern-matching as well
More information about the Haskell