Follow

Like, Haskell has monads because they want to preserve the sanctity of their pure-functional ecosystem. Side effects—which includes IO, the whole de rigueur of programming—are treated like unwelcome interlopers.

@djmoch One of the things that absolutely blew my mind about Haskell is that *every* program begins and ends in `main :: IO ()`

So rather than being an interloper, I think of IO as the “real” (or RealWorld) language and all the pure code is just a weak commitment/convention not to do IO things in a particular scope (weak because of seq and unsafePerformIO).

But while it’s totally possible to use Haskell like an imperative lang, it’s true the syntax and docs don’t make that particularly clear.

@johnburnham I’m by no means a Haskell expert, just an observer, but is using Haskell like an imperative language desirable? I guess I’m a bit confused by your point if it isn’t, as I suspect is the case.

@djmoch If you’re in the IO environment (and everything is, technically) then you can use IORefs for mutable variables, use things like forM or forever for looping. It’s not particularly low-level/“close to the metal”, but it certainly supports imperative-style programming.

As to whether it’s desirable, it depends. Often it’s better to put the bulk of your logic in the pure language. But not always. Sometimes things are just so causally entangled with RealWorld that staying in IO is better.

Sign in to participate in the conversation
Mastodon

A private Mastodon instance