8

The use case is an AWS Lambda function I want some data pre-loaded into it at compile time. How does one go about pre-populating data structures at compile time in Haskell? Analogous C++ discussion.

Community
  • 1
  • 1
Chad Brewbaker
  • 2,523
  • 2
  • 19
  • 26
  • My best stab so far is to use the C++ template abuse solution and FFI to it. Complete hack, I would rather do this all in Hask. – Chad Brewbaker Sep 20 '15 at 14:22
  • I don't believe this is really possible, since even if you have access to the constructors of a type you have to deal with lazy evaluation. If I put a list literal in a source file and load it into GHCi, `:sprint` shows that it hasn't been evaluated yet. The data is still stored in the binary, but the structure itself hasn't been "put together" yet. – bheklilr Sep 20 '15 at 14:30
  • 1
    I think it should be possible to achieve this with template-haskell. – Jakob Runge Sep 20 '15 at 14:43
  • There are some tricks you can play if you want unboxed vectors, where you use the fact that string literals are actually C strings. I don't remember the trick exactly, but I think it involves `Addr#` or some such. If you want anything with pointers in it, you're going to have much more trouble because of the linker and such, and at that point you should probably give up. – dfeuer Sep 20 '15 at 14:47
  • 2
    BTW, "Hask" is normally not used as shorthand for the name Haskell, but rather as the name of the mathematical almost-category of Haskell types and functions. – dfeuer Sep 20 '15 at 14:48
  • 1
    Can you be more specific about your problem? I could write a satisfactory answer if you showed me what exactly you needed doing. – AJF Sep 20 '15 at 16:53
  • Key value pair hash map. Keys could be either 64 bit ints or small strings. – Chad Brewbaker Sep 23 '15 at 03:34

0 Answers0