> You'd write code pretending it's pure while it really isn't.
in a way, it's the opposite! the point is you can't pretend, you have to make impurity painfully explicit:
getTradeTax :: CountryId -> CountryId -> IO Float
-- ^ sirens blaring, side-effect alert
getTradeTax ca cb = do
aInEu <- lookupEUMemberDB ca
bInEu <- lookupEUMemberDB cb
if (aInEu && bInEu)
then (pure 15.00) -- made up value
else getNonEUTradeTax ca cb -- another impure operation
there's the "IO" in the signature, and all the do-notation `<-`, ie syntactic sugar for `>>=`, piping the result into a callback. to use the Promise analogy again, `x <- foo` is kinda like `x = await foo` (but more general, bc Monads are cool)
> I can see part of the appeal, but I can do that in my current language.
true, and i've seen IO-monad-alikes for Python and JS, but most of the benefits come when every library you use has to be explicit about impurity and there's a typechecker enforcing it.
in a way, it's the opposite! the point is you can't pretend, you have to make impurity painfully explicit:
there's the "IO" in the signature, and all the do-notation `<-`, ie syntactic sugar for `>>=`, piping the result into a callback. to use the Promise analogy again, `x <- foo` is kinda like `x = await foo` (but more general, bc Monads are cool)> I can see part of the appeal, but I can do that in my current language.
true, and i've seen IO-monad-alikes for Python and JS, but most of the benefits come when every library you use has to be explicit about impurity and there's a typechecker enforcing it.