‹ BackHN Continuity

Thread

What Zig felt like, coming from Rust

282 points · 351 comments · ksec

  1. csense · · focus · HN ↗
    One of the section headings says "Mutation vs. immutable monad is the core difference" but this is not true.

    The code in that section is clear in its purpose and broad outline: "Give me a function and data; if the data is bare apply the function to it; if the data is a container apply the function to each item inside it."

    You can absolutely do that with immutable data structures in Zig. You just have to pass an allocator to the function (i.e. instead of calling data.flat_map(f), you call data.flat_map(a, f) where a is your allocator).

    That the Zig version of the code does mutation is a matter of programmer choice, not something imposed by the language.

    (Also, what do monads have to do with it?)

    1. kccqzy · · focus · HN ↗
      Monads are where flat_map came from. A monadic programming style is where flat_map is used pervasively eschewing other APIs.
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.