As an introductory example, here is the usual "Hello World" written in PureScript:
module Main where
import Effect.Console
main = log "Hello, World!"The following code defines a Person data type and a function to generate a string representation for a Person:
data Person = Person { name :: String, age :: Int }
showPerson :: Person -> String
showPerson (Person o) = o.name <> ", aged " <> show o.age
examplePerson :: Person
examplePerson = Person { name: "Bonnie", age: 26 }Line by line, this reads as follows:
Personis a data type with one constructor, also calledPerson- The
Personconstructor takes an object with two properties,namewhich is aString, andagewhich is anInt - The
showPersonfunction takes aPersonand returns aString showPersonworks by case analysis on its argument, first matching the constructorPersonand then using string concatenation and object accessors to return its result.examplePersonis a Person object, made with thePersonconstructor and given the String "Bonnie" for the name value and the Int 26 for the age value.
The full language reference continues below: