Banjo

52 thoughts
last posted Nov. 9, 2015, 7:13 p.m.

22 earlier thoughts

0

Monad do-blocks vs fluent method API

It might be interesting to compare the Haskell monad approach to a fluent interface:

do putStr "Enter your name: "
   name <- readString
   putStr "Hello, " ++ name

Possible similar code using method calls in Banjo:

io.putStr("Enter your name: ")
  .readString.if({
       string(io, name) = io.putStr("Hello, " + name)
       error(io) = io.quit
  })

Note the use of the visitor pattern on the readString result to pass in the success/failure of the operation. This is visually a bit messier than throwing an exception but it does make for very clear error handling.

29 later thoughts