SlideShare a Scribd company logo
All Aboard the Scala-
to-PureScript
Express!
John A. De Goes
What's Wrong with Scala?
Nothing... Scala Makes FP Possible
What's Wrong with Scala?
PureScript Makes FP Easy
• Syntax optimized for function definition & application
• Polymorphic functions
• Rank-n types
• Higher-kinded type inference
• Constraint inference
• Polymorphic row types (records, effects)
• Effect system for high performance, good reasoning
What's Wrong with Scala?
PureScript Is Just Like Scala!
• Strict, not lazy
• Good mapping of primitives to JVM
• Integer -> int, java.lang.Integer
• Number -> float, java.lang.Float
• String -> String1
• Boolean -> boolean, java.lang.Boolean
• Array a -> Java array
• Java-compatible FFI
• Import types
• Import (static) functions
• No story for methods
• Wrap, baby, wrap!
In Fact, The Core of Scala is... PureScript!
1
Not [Char] like Haskell!
PureScript Tour
Comments
// Single-line
/* Multi-line */
/** Scala doc */
-- Single-line
(* Multi-line *)
-- | PureScript doc
PureScript Tour
Literals
val bool = true -- Boolean
val int = 2 -- Integer
val float = 2.2 -- Float
val char = 'C' -- Char
val string = "foo" -- String
val tuple = (1, 2) -- Tuple2
let bool = true -- Boolean
let int = 2 -- Int
let float = 2.2 -- Number
let char = 'C' -- Char
let string = "foo" -- String
let array = [1, 2] -- Array Int
let record = {a: 1} -- Record
PureScript Tour
Local Variables (Let)
val dsquared = d * d
val distance = Math.sqrt(dsquared)
distance * 0.5
let
dsquared = d * d
distance = sqrt distance
in
distance * 0.5
PureScript Tour
Local Variables (Where)
halfDistance d = distance * 0.5
where
dsquared = d * d
distance = sqrt distance
PureScript Tour
Data: Products
case class Person(name: String, age: Int)
|
Type constructor
// Implicit data constructor:
// object Person { def apply(name: String, age: Int): Person = new Person(name, age) }
data Person = Person String Int
| |
Type Constructor Data Constructor
PureScript Tour
Data: Products w/Records
val sherlock = Person("Sherlock Holmes", 42)
let sherlock = Person "Sherlock Holmes" 42
PureScript Tour
Data: Products w/Records
data Person = Person {name :: String, age :: Int}
let sherlock = Person {name: "Sherlock Holmes", age: 42}
PureScript Tour
Data: Sums
sealed trait Option[A]
final case class Some[A](value: A) extends Option[A]
final case class None[A]() extends Option[A]
data Option a = Some a | None
PureScript Tour
Data: Sums
val somePerson: Option[Person] = Some(sherlock)
let somePerson = Some sherlock
PureScript Tour
Pattern Matching: Products
val name = sherlock match {
case Person(name, age) => name
}
let name = case sherlock of
Person name age -> name
PureScript Tour
Pattern Matching: Records
let name = case sherlock of
Person {name: n, age: a} -> n
PureScript Tour
Pattern Matching: Sums
val name = somePerson match {
case Some(Person(name, _)) => name
case None() => "Mary Smith"
}
let name = case somePerson of
Some (Person name _) -> name
None -> "Mary Smith"
PureScript Tour
Pattern Matching: Sums (w/Records)
let name = case somePerson of
Some (Person {name: name}) -> name
None -> "Mary Smith"
PureScript Tour
Types: Signatures (Definitions)
val nameExtractor : Person => String = _.name
nameExtractor :: Person -> String
nameExtractor (Person name _) = name
PureScript Tour
Types: Signatures (Inline)
val i = 3
(i * (2 : Int)) + 5
PureScript Tour
Types: Signatures (Inline)
let i = 3 in (i * (2 :: Int)) + 5
PureScript Tour
Types: Aliases
type Result[A] = Either[Error, A]
type Email = String
type Function[A, B] = A => B
type Result a = Either Error a
type Email = String
type Function a b = a -> b
PureScript Tour
Types: Records
type Person = { name :: String, age :: Int }
PureScript Tour
Types: Arrays
let intArray = [1, 2, 3] -- Array Int
PureScript Tour
Function Definition: Monomorphic
val squareIt : Float => Float = (x: Float) => x * x
squareIt :: Number -> Number
squareIt x = x * x
PureScript Tour
Function Definition: Monomorphic (Lambdas)
squareIt :: Number -> Number
squareIt = x -> x * x
PureScript Tour
Function Definition: Polymorphic
def second[A, B](tuple: (A, B)): B = tuple._2
second :: forall a b. Tuple a b -> b
second (Tuple _ b) = b
PureScript Tour
Function Definition: Higher Arity
def fullName(firstName: String, lastName: String): String = firstName + " " + lastName
val result = fullName("John", "Doe")
fullName :: String -> String -> String
fullName first last = first <> " " <> last
result = fullName "John" "Doe"
PureScript Tour
Function Definition: Higher Arity
myFunction :: a -> b -> c -> d -> e
-- Equivalent to:
myFunction :: a -> (b -> (c -> (d -> e)))
PureScript Tour
Function Application: Monomorphic
val squareIt : Float => Float = (x: Float) => x * x
squareIt(2.2)
squareIt :: Number -> Number
squareIt = x -> x * x
result = squareIt 2.2
PureScript Tour
Packages / Modules
package collections.immutable.list
// ...
module Collections.Immutable.List where
-- ...
PureScript Tour
Imports
package collections.immutable.list
import scalaz.(IList)
module Collections.Immutable.List where
-- No wildcard
import Data.Tuple(Tuple(..))
PureScript Tour
Exports
package object utils {
public def second[A, B](tuple: (A, B)) B = tuple._2
}
module Util (second) where
import Data.Tuple(Tuple(..))
second :: forall a b. Tuple a b -> b
second (Tuple _ b) = b
PureScript Tour
Type Classes
trait Semigroup[A] {
def append(a1: A, a2: A): A
}
implicit val StringSemigroup: Semigroup[String] {
def append(a1: String, a2: String): String = a1 + a2
}
class Semigroup a where
append :: a -> a -> a
instance stringSemigroup :: Semigroup String where
append a1 a2 = a1 <> a2
PureScript Tour
(Sync|Async) Effects
println("What is your name?")
val name = readLine()
println("Hello, " + name "!")
prints = do
println "What is your name?"
name <- readLine
println ("Hello, " <> name <> "!")
PureScript Tour
Effects
• No need to understand the monadic basis to get started
• Utilizes PureScript's polymorphic row types
• Different types of effects are labeled differently in a row of
effects
• Fine-grained effect tracking without performance overhead
THE END

More Related Content

What's hot (20)

PDF
Blazing Fast, Pure Effects without Monads — LambdaConf 2018
John De Goes
 
PDF
First-Class Patterns
John De Goes
 
PDF
The Next Great Functional Programming Language
John De Goes
 
PDF
Functor, Apply, Applicative And Monad
Oliver Daff
 
PDF
Introduction to functional programming using Ocaml
pramode_ce
 
PDF
One Monad to Rule Them All
John De Goes
 
PDF
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
Fwdays
 
PDF
Building a Tagless Final DSL for WebGL
Luka Jacobowitz
 
PDF
The Death of Final Tagless
John De Goes
 
PPTX
Kotlin as a Better Java
Garth Gilmour
 
PDF
ZIO Schedule: Conquering Flakiness & Recurrence with Pure Functional Programming
John De Goes
 
PDF
O caml2014 leroy-slides
OCaml
 
PDF
A taste of Functional Programming
Jordan Open Source Association
 
PPTX
Scala - where objects and functions meet
Mario Fusco
 
PDF
Hey! There's OCaml in my Rust!
Kel Cecil
 
PDF
Kotlin Bytecode Generation and Runtime Performance
intelliyole
 
PDF
The best of AltJava is Xtend
takezoe
 
PPTX
Functional Programming in Javascript - IL Tech Talks week
yoavrubin
 
PDF
3 kotlin vs. java- what kotlin has that java does not
Sergey Bandysik
 
PDF
2 kotlin vs. java: what java has that kotlin does not
Sergey Bandysik
 
Blazing Fast, Pure Effects without Monads — LambdaConf 2018
John De Goes
 
First-Class Patterns
John De Goes
 
The Next Great Functional Programming Language
John De Goes
 
Functor, Apply, Applicative And Monad
Oliver Daff
 
Introduction to functional programming using Ocaml
pramode_ce
 
One Monad to Rule Them All
John De Goes
 
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
Fwdays
 
Building a Tagless Final DSL for WebGL
Luka Jacobowitz
 
The Death of Final Tagless
John De Goes
 
Kotlin as a Better Java
Garth Gilmour
 
ZIO Schedule: Conquering Flakiness & Recurrence with Pure Functional Programming
John De Goes
 
O caml2014 leroy-slides
OCaml
 
A taste of Functional Programming
Jordan Open Source Association
 
Scala - where objects and functions meet
Mario Fusco
 
Hey! There's OCaml in my Rust!
Kel Cecil
 
Kotlin Bytecode Generation and Runtime Performance
intelliyole
 
The best of AltJava is Xtend
takezoe
 
Functional Programming in Javascript - IL Tech Talks week
yoavrubin
 
3 kotlin vs. java- what kotlin has that java does not
Sergey Bandysik
 
2 kotlin vs. java: what java has that kotlin does not
Sergey Bandysik
 

Similar to All Aboard The Scala-to-PureScript Express! (20)

PDF
Gentle Introduction to Scala
Fangda Wang
 
PDF
Ti1220 Lecture 7: Polymorphism
Eelco Visser
 
PDF
Modern Application Foundations: Underscore and Twitter Bootstrap
Howard Lewis Ship
 
PDF
Monads and Monoids by Oleksiy Dyagilev
JavaDayUA
 
PDF
An introduction to functional programming with Swift
Fatih Nayebi, Ph.D.
 
PDF
Grammarware Memes
Eelco Visser
 
PDF
Power of functions in a typed world
Debasish Ghosh
 
PDF
ScalaBlitz
Aleksandar Prokopec
 
PPTX
Javascript Basics
msemenistyi
 
PDF
Scala in Practice
Francesco Usai
 
PPTX
Unit 3 Compiler Design Regulation 2021.pptx
jeevitha404389
 
PPT
Scala introduction
Yardena Meymann
 
PDF
recap-js-and-ts.pdf
NuttavutThongjor1
 
PDF
Peyton jones-2009-fun with-type_functions-slide
Takayuki Muranushi
 
PDF
Functional programming in Scala
Damian Jureczko
 
PPTX
ES6: Features + Rails
Santosh Wadghule
 
PDF
Model-Driven Software Development - Static Analysis & Error Checking
Eelco Visser
 
PPTX
Academy PRO: ES2015
Binary Studio
 
PDF
So various polymorphism in Scala
b0ris_1
 
PDF
Scope Graphs: A fresh look at name binding in programming languages
Eelco Visser
 
Gentle Introduction to Scala
Fangda Wang
 
Ti1220 Lecture 7: Polymorphism
Eelco Visser
 
Modern Application Foundations: Underscore and Twitter Bootstrap
Howard Lewis Ship
 
Monads and Monoids by Oleksiy Dyagilev
JavaDayUA
 
An introduction to functional programming with Swift
Fatih Nayebi, Ph.D.
 
Grammarware Memes
Eelco Visser
 
Power of functions in a typed world
Debasish Ghosh
 
Javascript Basics
msemenistyi
 
Scala in Practice
Francesco Usai
 
Unit 3 Compiler Design Regulation 2021.pptx
jeevitha404389
 
Scala introduction
Yardena Meymann
 
recap-js-and-ts.pdf
NuttavutThongjor1
 
Peyton jones-2009-fun with-type_functions-slide
Takayuki Muranushi
 
Functional programming in Scala
Damian Jureczko
 
ES6: Features + Rails
Santosh Wadghule
 
Model-Driven Software Development - Static Analysis & Error Checking
Eelco Visser
 
Academy PRO: ES2015
Binary Studio
 
So various polymorphism in Scala
b0ris_1
 
Scope Graphs: A fresh look at name binding in programming languages
Eelco Visser
 
Ad

More from John De Goes (16)

PDF
Refactoring Functional Type Classes
John De Goes
 
PDF
Error Management: Future vs ZIO
John De Goes
 
PDF
Atomically { Delete Your Actors }
John De Goes
 
PDF
Scalaz Stream: Rebirth
John De Goes
 
PDF
Scalaz Stream: Rebirth
John De Goes
 
PDF
ZIO Queue
John De Goes
 
PDF
Scalaz 8: A Whole New Game
John De Goes
 
PDF
Streams for (Co)Free!
John De Goes
 
PDF
Getting Started with PureScript
John De Goes
 
PPTX
SlamData - How MongoDB Is Powering a Revolution in Visual Analytics
John De Goes
 
PPTX
The Dark Side of NoSQL
John De Goes
 
PDF
Quirrel & R for Dummies
John De Goes
 
PDF
In-Database Predictive Analytics
John De Goes
 
PDF
Analytics Maturity Model
John De Goes
 
PDF
Rise of the scientific database
John De Goes
 
PDF
Fun with automata
John De Goes
 
Refactoring Functional Type Classes
John De Goes
 
Error Management: Future vs ZIO
John De Goes
 
Atomically { Delete Your Actors }
John De Goes
 
Scalaz Stream: Rebirth
John De Goes
 
Scalaz Stream: Rebirth
John De Goes
 
ZIO Queue
John De Goes
 
Scalaz 8: A Whole New Game
John De Goes
 
Streams for (Co)Free!
John De Goes
 
Getting Started with PureScript
John De Goes
 
SlamData - How MongoDB Is Powering a Revolution in Visual Analytics
John De Goes
 
The Dark Side of NoSQL
John De Goes
 
Quirrel & R for Dummies
John De Goes
 
In-Database Predictive Analytics
John De Goes
 
Analytics Maturity Model
John De Goes
 
Rise of the scientific database
John De Goes
 
Fun with automata
John De Goes
 
Ad

Recently uploaded (20)

PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Python basic programing language for automation
DanialHabibi2
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 

All Aboard The Scala-to-PureScript Express!

  • 1. All Aboard the Scala- to-PureScript Express! John A. De Goes
  • 2. What's Wrong with Scala? Nothing... Scala Makes FP Possible
  • 3. What's Wrong with Scala? PureScript Makes FP Easy • Syntax optimized for function definition & application • Polymorphic functions • Rank-n types • Higher-kinded type inference • Constraint inference • Polymorphic row types (records, effects) • Effect system for high performance, good reasoning
  • 4. What's Wrong with Scala? PureScript Is Just Like Scala! • Strict, not lazy • Good mapping of primitives to JVM • Integer -> int, java.lang.Integer • Number -> float, java.lang.Float • String -> String1 • Boolean -> boolean, java.lang.Boolean • Array a -> Java array • Java-compatible FFI • Import types • Import (static) functions • No story for methods • Wrap, baby, wrap! In Fact, The Core of Scala is... PureScript! 1 Not [Char] like Haskell!
  • 5. PureScript Tour Comments // Single-line /* Multi-line */ /** Scala doc */ -- Single-line (* Multi-line *) -- | PureScript doc
  • 6. PureScript Tour Literals val bool = true -- Boolean val int = 2 -- Integer val float = 2.2 -- Float val char = 'C' -- Char val string = "foo" -- String val tuple = (1, 2) -- Tuple2 let bool = true -- Boolean let int = 2 -- Int let float = 2.2 -- Number let char = 'C' -- Char let string = "foo" -- String let array = [1, 2] -- Array Int let record = {a: 1} -- Record
  • 7. PureScript Tour Local Variables (Let) val dsquared = d * d val distance = Math.sqrt(dsquared) distance * 0.5 let dsquared = d * d distance = sqrt distance in distance * 0.5
  • 8. PureScript Tour Local Variables (Where) halfDistance d = distance * 0.5 where dsquared = d * d distance = sqrt distance
  • 9. PureScript Tour Data: Products case class Person(name: String, age: Int) | Type constructor // Implicit data constructor: // object Person { def apply(name: String, age: Int): Person = new Person(name, age) } data Person = Person String Int | | Type Constructor Data Constructor
  • 10. PureScript Tour Data: Products w/Records val sherlock = Person("Sherlock Holmes", 42) let sherlock = Person "Sherlock Holmes" 42
  • 11. PureScript Tour Data: Products w/Records data Person = Person {name :: String, age :: Int} let sherlock = Person {name: "Sherlock Holmes", age: 42}
  • 12. PureScript Tour Data: Sums sealed trait Option[A] final case class Some[A](value: A) extends Option[A] final case class None[A]() extends Option[A] data Option a = Some a | None
  • 13. PureScript Tour Data: Sums val somePerson: Option[Person] = Some(sherlock) let somePerson = Some sherlock
  • 14. PureScript Tour Pattern Matching: Products val name = sherlock match { case Person(name, age) => name } let name = case sherlock of Person name age -> name
  • 15. PureScript Tour Pattern Matching: Records let name = case sherlock of Person {name: n, age: a} -> n
  • 16. PureScript Tour Pattern Matching: Sums val name = somePerson match { case Some(Person(name, _)) => name case None() => "Mary Smith" } let name = case somePerson of Some (Person name _) -> name None -> "Mary Smith"
  • 17. PureScript Tour Pattern Matching: Sums (w/Records) let name = case somePerson of Some (Person {name: name}) -> name None -> "Mary Smith"
  • 18. PureScript Tour Types: Signatures (Definitions) val nameExtractor : Person => String = _.name nameExtractor :: Person -> String nameExtractor (Person name _) = name
  • 19. PureScript Tour Types: Signatures (Inline) val i = 3 (i * (2 : Int)) + 5
  • 20. PureScript Tour Types: Signatures (Inline) let i = 3 in (i * (2 :: Int)) + 5
  • 21. PureScript Tour Types: Aliases type Result[A] = Either[Error, A] type Email = String type Function[A, B] = A => B type Result a = Either Error a type Email = String type Function a b = a -> b
  • 22. PureScript Tour Types: Records type Person = { name :: String, age :: Int }
  • 23. PureScript Tour Types: Arrays let intArray = [1, 2, 3] -- Array Int
  • 24. PureScript Tour Function Definition: Monomorphic val squareIt : Float => Float = (x: Float) => x * x squareIt :: Number -> Number squareIt x = x * x
  • 25. PureScript Tour Function Definition: Monomorphic (Lambdas) squareIt :: Number -> Number squareIt = x -> x * x
  • 26. PureScript Tour Function Definition: Polymorphic def second[A, B](tuple: (A, B)): B = tuple._2 second :: forall a b. Tuple a b -> b second (Tuple _ b) = b
  • 27. PureScript Tour Function Definition: Higher Arity def fullName(firstName: String, lastName: String): String = firstName + " " + lastName val result = fullName("John", "Doe") fullName :: String -> String -> String fullName first last = first <> " " <> last result = fullName "John" "Doe"
  • 28. PureScript Tour Function Definition: Higher Arity myFunction :: a -> b -> c -> d -> e -- Equivalent to: myFunction :: a -> (b -> (c -> (d -> e)))
  • 29. PureScript Tour Function Application: Monomorphic val squareIt : Float => Float = (x: Float) => x * x squareIt(2.2) squareIt :: Number -> Number squareIt = x -> x * x result = squareIt 2.2
  • 30. PureScript Tour Packages / Modules package collections.immutable.list // ... module Collections.Immutable.List where -- ...
  • 31. PureScript Tour Imports package collections.immutable.list import scalaz.(IList) module Collections.Immutable.List where -- No wildcard import Data.Tuple(Tuple(..))
  • 32. PureScript Tour Exports package object utils { public def second[A, B](tuple: (A, B)) B = tuple._2 } module Util (second) where import Data.Tuple(Tuple(..)) second :: forall a b. Tuple a b -> b second (Tuple _ b) = b
  • 33. PureScript Tour Type Classes trait Semigroup[A] { def append(a1: A, a2: A): A } implicit val StringSemigroup: Semigroup[String] { def append(a1: String, a2: String): String = a1 + a2 } class Semigroup a where append :: a -> a -> a instance stringSemigroup :: Semigroup String where append a1 a2 = a1 <> a2
  • 34. PureScript Tour (Sync|Async) Effects println("What is your name?") val name = readLine() println("Hello, " + name "!") prints = do println "What is your name?" name <- readLine println ("Hello, " <> name <> "!")
  • 35. PureScript Tour Effects • No need to understand the monadic basis to get started • Utilizes PureScript's polymorphic row types • Different types of effects are labeled differently in a row of effects • Fine-grained effect tracking without performance overhead