this post was submitted on 02 Jul 2023
197 points (94.6% liked)

Programmer Humor

19515 readers
1182 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[โ€“] expr 3 points 1 year ago (1 children)

I think that's a reasonable enough generalization, yeah.

I'm sorry though, I seem to have given you incorrect information. Apparently that library does not have monad instances, so it's a bad example (though the Concurrently type does have an applicative instance, which is similar in concept, just less powerful). For some reason I thought they also provided monad instances for their API. My bad.

Perhaps it would be better to use a much simpler example in Option. The semantics of the sequencing of Options is that the final result will be None if any of the sequenced Options had a value of None, otherwise it would be a Some constructor wrapping the final value. So the semantics are "sequence these operations, and if any fail, the entire block fails", essentially. Result is similar, except the result would be the first Err that is encountered, otherwise it would be a final Ok wrapping the result.

So each type can have its own semantics of sequencing operations, and in languages that can express it, we can write useful functions that work for any monad, allowing the caller of said function to decide what sequencing semantics they would like to use.

[โ€“] technohacker 2 points 1 year ago

All good, thanks for the explanation! :D