Logging in a strictly typed programming language like PureScript do not work as simple as in JavaScript. Or does it?
The basic way is to use the log method from puresript-console package.
import Effect.Console (log)
main :: Unit
= do
main log "This will be shown in the console"
Two things are to mention here:
For the second point we can replace the log function with the logShow function. The difference is that the data structure you will log, need to be part of the Show typeclass (hence, probably implement or derive the show method).
Many would find the solution above and stop here. In many cases it is sufficient, it is not wrong to do so.
Another way is the purescript-debug package. Here you can find the traceM function. This differs in two ways from the log function above:
Here is an example how to log in PureScript with debug:
import Debug (traceM)
main :: Unit
= do
main
traceM thingwhere
= { name: "Test", purpose: "Logging" } thing
It is on you to decide what you prefer, another dependency in your project or the ease of use of traceM.
Thank you for reading this far! Let’s connect. You can @ me on X (@debilofant) with comments, or feel free to follow. Please like/share this article so that it reaches others as well.