Haskell can help you with "O(n)", "less than 1MB" and many other constraints of that sort.
You should use domain-specific language embedded into it for that.
If you do that that way, Haskell can help you with particular details of the implementation with types (I think that O(n) would be easy - I did parametrization on the length circa 2008) and help you to connect your implementation and the rest of program, again, with types.
I did exactly that. From well-typed parsers for stream processing hardware to (not-so-well typed for historical reasons) strict realtime algorithms.