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
Deep Dive Into Swift
Sarath C
 
PPTX
Scala fundamentals
Alfonso Ruzafa
 
PDF
Infinum iOS Talks #1 - Swift done right by Ivan Dikic
Infinum
 
PDF
Lecture 5
Muhammad Fayyaz
 
PDF
The Swift Compiler and Standard Library
Santosh Rajan
 
PDF
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
GeeksLab Odessa
 
PDF
Scala in Places API
Łukasz Bałamut
 
PPTX
Scala for curious
Tim (dev-tim) Zadorozhniy
 
PDF
From android/java to swift (3)
allanh0526
 
PPT
Scala - brief intro
Razvan Cojocaru
 
PDF
Introduction to Go
Jaehue Jang
 
PDF
Go 프로그래밍 소개 - 장재휴, DomainDriven커뮤니티
JaeYeoul Ahn
 
PDF
Scala: Functioneel programmeren in een object georiënteerde wereld
Werner Hofstra
 
PDF
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kirill Rozov
 
PDF
Lego: A brick system build by scala
lunfu zhong
 
PDF
Cocoa Design Patterns in Swift
Michele Titolo
 
PDF
Idioms in swift 2016 05c
Kaz Yoshikawa
 
PDF
Scala for Java Programmers
Eric Pederson
 
PPT
Python 101 language features and functional programming
Lukasz Dynowski
 
PPTX
API Development and Scala @ SoundCloud
Bora Tunca
 
Deep Dive Into Swift
Sarath C
 
Scala fundamentals
Alfonso Ruzafa
 
Infinum iOS Talks #1 - Swift done right by Ivan Dikic
Infinum
 
Lecture 5
Muhammad Fayyaz
 
The Swift Compiler and Standard Library
Santosh Rajan
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
GeeksLab Odessa
 
Scala in Places API
Łukasz Bałamut
 
Scala for curious
Tim (dev-tim) Zadorozhniy
 
From android/java to swift (3)
allanh0526
 
Scala - brief intro
Razvan Cojocaru
 
Introduction to Go
Jaehue Jang
 
Go 프로그래밍 소개 - 장재휴, DomainDriven커뮤니티
JaeYeoul Ahn
 
Scala: Functioneel programmeren in een object georiënteerde wereld
Werner Hofstra
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kirill Rozov
 
Lego: A brick system build by scala
lunfu zhong
 
Cocoa Design Patterns in Swift
Michele Titolo
 
Idioms in swift 2016 05c
Kaz Yoshikawa
 
Scala for Java Programmers
Eric Pederson
 
Python 101 language features and functional programming
Lukasz Dynowski
 
API Development and Scala @ SoundCloud
Bora Tunca
 
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)

PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PPTX
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PDF
UiPath Agentic AI ile Akıllı Otomasyonun Yeni Çağı
UiPathCommunity
 
PDF
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
PDF
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
PDF
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PDF
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
PDF
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
PDF
The Growing Value and Application of FME & GenAI
Safe Software
 
PPTX
Simplifica la seguridad en la nube y la detección de amenazas con FortiCNAPP
Cristian Garcia G.
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PPTX
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
PDF
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
UiPath Agentic AI ile Akıllı Otomasyonun Yeni Çağı
UiPathCommunity
 
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
The Growing Value and Application of FME & GenAI
Safe Software
 
Simplifica la seguridad en la nube y la detección de amenazas con FortiCNAPP
Cristian Garcia G.
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 

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