3 ms·
Looks like this "pays for itself" (as in https://prog21.dadgum.com/136.html https://prog21.dadgum.com/136.html ), which is always nice to see for a simplificati
by chriswarbo 8y ago
Looks like this "pays for itself" (as in https://prog21.dadgum.com/136.html https://prog21.dadgum.com/136.html ), which is always nice to see for a simplification :)
The top-level `Map` example resonated with me, since I recently needed to speed up some scripts which look up data from some statically-known JSON files, which match some user-provided properties. I was using `jq`, but ended up doing an O(N^2) nested loop which was too slow. I wrote a Haskell version, which was easy enough with the Aeson library, but then I was able to speed it up massively by using Template Haskell to read the files, parse the JSON and build a `Map` from properties to data at compile time. This is encoded in the resulting program as a top-level definition, just like the example shown in this article. The resulting binary only needs to do an O(log N) lookup at runtime, which is more than acceptable :)