Purescript #3

Call me old school but debugging in a console program is all about writing to stdout or stderr. In my day-to-day programming (when I get the opportunity) that’s easily done: sprinkle the right printf / puts/ log / printlncall throughout the code. But in a strongly typed language like Purescript?

How can we see what our makeMeAString function is actually doing? We could sprinkle it with log or logShow from the Contol.Monad.Aff module but that then adds a CONSOLE effect to the function; if makeMeAString was buried several level deep in a callstack then that would mean adding CONSOLE to every single function. That’s just not going to cut it, especially as after finding the problem we’d then have to remove all of that.

@paf31 came through on Twitter with a much better suggestion:

With purescript-debug we can see the values as they pass through makeMeAString by using the spy :: a -> a function:

No effects needed.

There are other functions in purescript-debug that help old timers like myself. I was lucky to find the problem using just spy.

If you’re interested purescript-debug uses Javascript to log to the console: it effectively lies about not writing to the console! I’m cool with that considering that it’s used for debugging, which is temporal.