H2JVM - A Haskell Library for writing JVM Bytecode
evincar:
instead of storing a list in reverse order you can use a DList
I’m always suspicious of DList in that physically it is essentially storing a list in reverse order, just less clearly: each closure is closing over one new element (actually, over another closure capturing that element) and over the closure recursively referencing the rest of the elements, which is the same structure as a cons cell (in either case, a data structure with two pointers, one pointing to the head and one to the tail), but less explicitly and with extra allocation/indirection (because each element is stored via an additional closure).
Something along the lines of reverse-list feels like a better approach—just a newtype wrapper around a regular list, to make clear that it’s in reverse order. I’ve never used that package, and I’ve always just been temped to make my own wrapper local to a project, allowing just two operations: snoc and toList.
Anyway, side issue but just wanted to share my critique of DList.
Discussion in the ATmosphere