Remix.run Logo
dnautics 11 hours ago

io is not a monad. theres nothing stopping you from stashing a global io "object" and just passing the global wherever you interface with the stdlib.

It's dependency injection. and yes, you can model dependecies like a monad but most people, even in less pure fp langs, don't.

i don't really say this to just be a pedant, but if you're an fp enjoyer, you will be disappointed if you get the picture that zig is fp-like, outside of a few squint-and-it-looks-like things

tux1968 11 hours ago | parent | next [-]

My reading of the article, was that the author seems to be in search of a new paradigm, that moves beyond what he sees as the limitations of "fp-like" languages as they exist today. His point appears to be that Zig provides the benefits of "fp-like" languages that exist today, while avoiding at least some of the downsides.

And he does admit you may have to squint, to appreciate the fp capabilities provided by Zig.

HelloNurse 6 hours ago | parent [-]

It is worth noting that some rather "enlightened" type system features are common in other imperative languages, not particularly novel ides in Zig.

For example Swift enums, while in some ways clunky, can do a decent job both as newtypes and as sum types (unlike Java enums, which are a fixed collection of instances of the same class).

danieltanfh95 10 hours ago | parent | prev [-]

I am not even sure if its a general pattern (inject any dependency?) or a specific pattern they added to Zig

dnautics 10 hours ago | parent [-]

idk in elixir we basically do exactly whats happening with io parameters when mocking or swapping implementations that all satisfy the same behaviour.

here. i am not the only one that refers to it as dependency injection:

https://daily.dev/blog/zig-async-io-io-uring-zig-0-16-rethin...

"Zig 0.16 introduces std.Io, a flexible I/O abstraction that uses dependency injection, similar to the Allocator interface"

danieltanfh95 9 hours ago | parent [-]

Sigh. I meant that the zig authors did not make it a general pattern and just slapped on the DI pattern specifically for io, instead of generalising the abstraction so people can DI stuff.