PureScript Tutorial 1
Ray Shih
What is PureScript
• PureScript is
• A pure functional language
• compiles to JavaScript
• like Haskell
Why PureScript
Why Pure Functional
Language
Why Pure Functional
• Referential Transparency ???
• Composability ???
Easier to understand
x = x + 1
so x = ?
Easier to understand
• Easier to build large program
• Easier to parallelize
• Easier to test
Why not ___ ?
• JavaScript
• No type checking
• FlowType/TypeScript?
• OK, but can you enforce it?
• Ugly syntax
Why not ___ ?
• Haskell (ghcjs)
• Way too heavy
Why not ___ ?
• ELM
• No generic (less fun)
• Elm Is Wrong
• only work for certain env
Why PureScript ??
Fun!
Env setup
Setup Env
• try.purescript.org
• install psc, bower, npm
• pulp init — init project
• pulp psci — interactive env
• pulp run — run
Hello world!
Chapter 3:

Functions and Records
Chapter 3:

Functions and Record
• Simple Types
• Number, String, Boolean
• Array
• Record (this is very different from Haskell)
• Function
• Define/Invoke
• Quantified Type
• Curried
• infix
• compose
• Define Types
Simple Types
• Number
• 3 :: Int
• 4.0 :: Number
• String
• “Hello world” :: String
• Boolean
• true :: Boolean
• Array
• [1,2,3] :: Array Int
Record
Function
Curried Functions
Infix Function Application
Function composition
Function composition 2
Where clause
Define Type!
Chapter 4: Recursion, Maps
and Folds
• Recursion
• fib
• map, filter, flatten
• concatMap
• Do notation
• Guard
• Folds
Recursion: Fib
Recursion on Array
map
filter, flatten
concatMap
Do notation
Do notation
Do notation
Do notation
Folds
Chapter 5: Pattern Matching
• Simple
• Guards
• Array
• Record Patterns and Row polymorphism
• Named
• case of
• partial
• ADT — data, newtype
Simple, Guard
Array Patterns
Record &

Row Polymorphism
Named
Case Expressions
Partial
Algebraic Data Type
newtype
References
• Frontend framework comparison

PureScript Tutorial 1