Crosscut

Daily Thought - 2024-07-06

Hey, I'm Hanno! These are my daily thoughts on Crosscut, the programming language I'm creating. If you have any questions, comments, or feedback, please get in touch!

This thought was published before Crosscut was called Crosscut! If it refers to "Caterpillar", that is the old name, just so you know.

< back to list

So, how do you track I/O in a functional language? Haskell does it by encoding I/O operations into a monad. (If you don't know what a monad is, then for the purpose of this discussion, just think it as a container for data that describes a series of I/O operations.) That monad is returned to the runtime, which executes the operations.

I think I understand why Haskell does it like that, but it's not how I want to do it in Caterpillar. Instead, I want to represent anything that can do I/O (like a file, for example) as values. A function that writes to a file needs to take the value representing that file as an argument, and return an updated version, which represents the file after it's been written to.

That way, the developer, the compiler, or the runtime, can clearly see the file value going through that function. I think this requires linear (or affine) types though, and that's probably the reason Haskell uses the (seemingly) more complicated monad-based technique. (I don't have enough room left to explain linear types today, but I'm sure I'll get to them sooner or later.)

<< previous thoughtnext thought >>

Hey, you! Want to subscribe to my daily thoughts? Just let me know (maybe include a nice message, if you're up for it), and I'll send you an email whenever I post a new one.