3 ms·
It's not really Rust's compiler that 'optimises lazy sequences'. It's LLVM, which notices that the code emitted happens to be able to be optimised down, if you
by memefrog 3y ago
It's not really Rust's compiler that 'optimises lazy sequences'. It's LLVM, which notices that the code emitted happens to be able to be optimised down, if you run it for a really, really long time with some very strong optimisations.
GHC would be a better example, I think. It performs stream fusion. This means it can turn 'map f (map g xs)' into 'map (f . g) xs', and of course it gets more complex than that, but that's the basics. It directly optimises lists (which, this being Haskell, are lazy sequences).
- vbezhenar 3y ago> GHC would be a better example, I think. It performs stream fusion. This means it can turn 'map f (map g xs)' into 'map (f . g) xs', and of course it gets more complex than that, but that's the basics. It directly optimises lists (which, this being Haskell, are lazy sequences). Is it for built-in map or it would work in a general way for, say, `myMap f (myMap g xs)` ?
- consilient 3y ago> Is it for built-in map or it would work in a general way for, say, `myMap f (myMap g xs)` ? Just the stdlib `map`, but it's all ordinary library code. You can easily add your own rewrite rules.