marick / fp-oo

Code samples and exercise solutions for /Functional Programming for the Object-Oriented Programmer/
143 stars 50 forks source link

16.4 Exercise - NullPointerException #34

Closed robermann closed 11 years ago

robermann commented 11 years ago

(with-monad sequence-monad (domonad [a [1 nil 3] b [-1 1]] (* a b)))

Returns: NullPointerException clojure.lang.Numbers.ops (Numbers.java:942)

And not, as suggested on 16.4 Exercise ("fastidious flounder" version): ` (-1 1 nil nil -3 3)

marick commented 11 years ago

You used sequence-monad instead of the combined monad. (Which is annoyingly called maybe-sequence-monad in the text, but combined-monad in my solution.) I'll improve the text.

robermann commented 11 years ago

When I read this sentence:

If decider had passed the nil to the next step, and then that step had checked, seen the nil, and returned nil instead of (* a b), there would be two nils in the result.

I thought that a plain Sequence monad would had produced two nils.