Title here
Summary here
Here’s the translated code from Go to PureScript, along with explanations in Markdown format suitable for Hugo:
In PureScript, variables are explicitly declared and used by the compiler to check type-correctness of function calls.
module Main where
import Effect.Console (log)
main :: Effect Unit
main = do
-- `let` declares a variable within a do block
let a = "initial"
log a
-- You can declare multiple variables at once
let b = 1
c = 2
log $ show b <> " " <> show c
-- PureScript infers the type of initialized variables
let d = true
log $ show d
-- Variables declared without initialization are not allowed in PureScript
-- Instead, we can use Maybe type to represent potential absence of value
let e :: Maybe Int
e = Nothing
log $ show e
-- In PureScript, all bindings are immutable by default
let f = "apple"
log f
To run this program, you would typically use the PureScript compiler (purs
) and Node.js:
$ pulp run
initial
1 2
true
Nothing
apple
In PureScript:
let
within a do block or at the top level of a module.let
block.Maybe
type to represent potentially absent values.:=
syntax for reassignment.print
or println
are replaced with log
from the Effect.Console
module.PureScript is a strongly-typed, purely functional language, so it handles variables and state differently from imperative languages. The focus is on immutability and explicit handling of side effects.