KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Like many a foolhardy pioneer before me, I'm endeavoring to cross the trackless wasteland that is Understanding Monads. I'm still staggering through, but I can't help noticing a certain monad-like quality about Python's with statement. Consider this fragment: with open(input_filename, 'r') as f: for line in f: process(line) Consider the open() call as the "unit" and the block itself as the "bind". The actual monad isn't exposed (uh, unless f is the monad), but the pattern is there. Isn't it? Or am I just mistaking all of FP for monadry? Or is it just 3 in the morning and anything seems plausible? A related question: if we have monads, do we need exceptions? In the above fragment, any failure in the I/O can be hidden from the code. Disk corruption, the absence of the named file, and an empty file can all be treated the same. So no need for a visible IO Exception. Certainly, Scala's Option typeclass has eliminated the dreaded Null Pointer Exception . If you rethought numbers as Monads (with NaN and DivideByZero as the special cases)... Like I said, 3 in the morning.
Tags (comma-separated)
Save Edits
Cancel