Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 1.48 KB

README.md

File metadata and controls

45 lines (32 loc) · 1.48 KB

PureScript Language Reference

As an introductory example, here is the usual "Hello World" written in PureScript:

module Main where

import Effect.Console

main = log "Hello, World!"

Another Example

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:

  • Person is a data type with one constructor, also called Person
  • The Person constructor takes an object with two properties, name which is a String, and age which is an Int
  • The showPerson function takes a Person and returns a String
  • showPerson works by case analysis on its argument, first matching the constructor Person and then using string concatenation and object accessors to return its result.
  • examplePerson is a Person object, made with the Person constructor and given the String "Bonnie" for the name value and the Int 26 for the age value.

The full language reference continues below:

  1. Types
  2. Syntax
  3. Type Classes
  4. Pattern Matching
  5. Modules
  6. FFI
  7. Records
  8. Roles
  9. Differences from Haskell