Remix.run Logo
shiandow 6 hours ago

That is interesting, I hadn't really given it much thought but my first instinct would be to assume the algebra in algebraic effect was not about having algebra like definitions but was in fact a direct reference to an algebra of a monad (though that might be the same thing).

At least the monad algeba gives a nice hint on how to view algbraic effects. Instead of using a monad so you can raise an exception

    f :: a -> E b
You use an E-algebra (h :: E a -> a) instead to create a function that takes both an input and an exception handler to produce an output

    g :: (a, E b -> b) -> b
The canonical example being something like

    g x h = h (f x)
And a simple example of a handler being something like a default value

    h :: Maybe a -> a
    h Some x = x
    h None   = default_value
With the advantage of course that given a handler you can be much more flexible in how you handle exceptions and where. You're not limited to just returning early, you can handle the exception and carry on.