Here’s the translation of the Go code to PureScript, formatted in Markdown suitable for Hugo:
Our first program will work with directories in the file system. Here’s the full source code:
To run the program, save it as Directories.purs and use spago run.
This PureScript code demonstrates working with directories:
We use the Node.FS.Sync module for file system operations.
mkdir creates a new directory.
mkdir' creates a directory hierarchy (similar to mkdir -p).
readdir lists directory contents.
chdir changes the current working directory.
We implement a recursive visitDir function to walk through directories.
Note that PureScript, being a functional language, handles effects differently from imperative languages. The Effect monad is used to represent side effects, and we use do notation for sequencing these effects.
Also, error handling in this example is simplified. In a production environment, you’d want to handle potential errors more robustly.