Iterator-based programming vs. functional programming

Henry Baker’s papers are marvelous, aren’t they? I remember 20+ years ago, reading aboout “the stack as a nursery”. Revelatory.

can you link it? https://dl.acm.org/profile/81452615666/publications?Role=author doesn’t bring it up.

I have no particular feelings about Rust except that it is a nice option for fans of statically typed functional programming languages when they need performance similar to C and C++. I don’t necessarily want to trade better performance for longer compile times or longer garbage collection pauses in OCaml, but I’d be happy to take any performance gains to be made with low hanging fruit that won’t affect my user experience.

There is room for OCaml and Rust to coexist as the right tool for different jobs.

The main thing I wanted to say, though, is that there are many garbage collected languages which offer unboxed types, though it is true that many other languages do box everything. Some examples of garbage collected languages which offer unboxed types (in addition to boxed types):

  • Go
  • C#
  • Nim
  • Julia
  • D

So, it is certainly possible to unbox things in a GC’d language. It’s just a challenge and you may have to compromise somewhere. It is certainly a big win for numeric computation because it not only avoids the cost of pointer chasing, but if also allows data in arrays to be inlined which improves cache performance and allows CPU optimizations like SIMD to be applied in some cases.

The trade is that this kind of optimizations in OCaml would massively slow down the compiler, since it would have to compile specialized versions of every polymorphic function. Currently, they just compile once and pass pointers around blindly. It’s a trade-off.

Regarding iterators, there are ways to apply transformations over a sequence which don’t have to construct intermediate containers. I’m working on a transducer library for this at the moment, but I think Base.Sequence accomplishes the same thing and the performance is fairly good.

1 Like
  • o
  • C#
  • Nim
  • Julia
  • D

Perhaps add mlton to the list (Mlton Features). It has unboxed/untagged ints, reals, words and unboxed native arrays. But alas it is not multicore. :wink:

3 Likes

Like the last time that Chet mentioned Baker, he probably referred to “ CONS should not CONS its arguments, part II: Cheney on the M.T.A.” / “CONS should not CONS its arguments, or, a lazy alloc is a smart alloc”.

Like the last time that I mentioned Baker, I referred to “Linear Logic and Permutation Stacks–The Forth Shall Be First” / “‘Use-Once’ Variables and Linear Objects–Storage Management, Reflection and Multi-Threading”

Baker’s website appears to be down but there is an archive here if you want to read them in HTML form.

2 Likes

it is curious to come across forth here.

1 Like

a |.> f b c d rewritten to f a b c d

Definitely a must-have, from my point of view !