Input and Output in PureScript
To log something in the console, make sure to import the proper package. Then, in the main function, we can log like this:
import Effect (Effect)
main = log "Hello world"Logging more than one thing
Section titled “Logging more than one thing”To run more than one thing in the main function, we need to use the do-keyword an proper indentation:
main = do log "Hello world" log "Hello World"Logging an expression
Section titled “Logging an expression”In case of a variable:
name = "John Doe"
main = log (show name)In case of a function-call:
double :: Int -> Intdouble x = x * 2
main = log (show (double 2))This will get “4” logged. Surprise! Please notice the additional braces around the function-call. Optionally, store the function call in a variable before logging.
Concatinating stuff in the console
Section titled “Concatinating stuff in the console”In this example, we have a function for doubling an integer. The second function calls the first one, but converts and returns the first ones value to a string. Plus, it concatinates it with another string:
doubleNumber :: Int -> IntdoubleNumber x = x * 2
printDoubleNumber :: Int -> StringprintDoubleNumber x = "The Result: " <> (show (doubleNumber x))
main = log (printDoubleNumber 2)In the console: “The Result: 4”