>>108448659
>The point I'm trying to make is that all error handling is already monadic
ok, here is an implementation of a maybe monad in the simplest language that does not have baked in support, notice when i use the monad i never handle the error? in fact i do not even have to think about errors, because that is what the bind function does for me. this is what monadic error handling is.
>Haskell simply abstracts out this pattern so that you don't have to write boilerplate.
if you are writing idiomatic haskell you are writing substantially different code than idiomatic go. i am not familiar with go, but i am use u can implement monadic operations with its compile time generics.
(define maybe-monad
(let ((the-nothing '(nothing))
(the-just '(just)))
(define (just v)
(list the-just v))
(define (just? v)
(and (pair? v) (eq? (car v) the-just)))
(define (nothing)
the-nothing)
(define (nothing? v)
(eq? the-nothing v))
(define (bind v f)
(if (nothing? v)
(nothing)
(f (cadr v))))
(lambda (m)
(case m
((just maybe) just)
((just?) just?)
((nothing) nothing)
((bind) bind)))))
(define (// x y)
(if (zero? y)
((maybe-monad 'nothing))
((maybe-monad 'just) (/ x y))))
(define (** x y)
((maybe-monad 'just) (* x y)))
(let ((maybe (maybe-monad 'maybe))
(bind (maybe-monad 'bind)))
(chain (maybe 20)
(bind _ (λ (x) (// x 10)))
(bind _ (λ (x) (** x 2)))
(bind _ (λ (x) (// x 0)))
(bind _ (λ (x) (** x 3)))
(bind _ (λ (x) (** x 12)))))