SlideShare uma empresa Scribd logo
1 de 46
Baixar para ler offline
Learn You a Frege for Great Good!
Pure functional programming language for JVM
CheshireCat (@y_taka_23)
Tokyo Kabukiza.tech Meetup #9 (2016/03/20)
Who am I?
● Name : CheshireCat
○ Twitter: @y_taka_23
○ GitHub: y-taka-23
● Favorites
○ Haskell
○ Formal methods (Coq, Alloy, SPIN etc...)
● (Would-be) Frege evangelist
“Frege is a Haskell for JVM”
Agenda
● What is Frege?
○ Basic features
○ Compatibility with Haskell
● Frege as a JVM language
○ How to deal the impurity
○ Java interoperation
1. What is Frege?
Frege’s Essence
● Pure, non-strict functional language
● Strictly-typed, Hindley-Milner type inference
● Java interoperation with elegance
“Hello, World” in Haskell
module Hello where
greeting :: String -> String
greeting name = “Hello, ” ++ name
main :: IO ()
main = do
putStrLn $ greeting “World”
“Hello, World” in Frege
module Hello where
greeting :: String -> String
greeting name = “Hello, ” ++ name
main :: [String] -> IO ()
main args = do
putStrLn $ greeting “World”
That’s the spitting image!
“Learn you a Haskell” Translation
● All example snipets into Frege
○ https://github.com/y-taka-23/learn-you-a-frege
● Compilable even in “dead-copied” translation
Compatibility with Haskell
● Syntax, standard libs : almost compatible!
● Hard to use in “practical” Haskell
○ External dependencies
○ Most of GHC extensions
○ Template Haskell
● Java interoperation is necessary
2. Frege as a JVM Language
Advantage of JVM Languages
● Platform-independent
○ Frege compiler generates Java source codes
● Feel free to invoke Java libraries
○ But pretty different regarding side-effects
■ Frege : Pure
■ Java : Impure, objects have own states
Can we invoke Java in nicer way
with Frege’s purity?
“Levels” of Java’s Impurity
● Immutable
○ ???
● Mutable, but without I/O
○ ???
● With I/O
○ ???
“Levels” of Java’s Impurity
● Immutable
○ Maps to Frege’s data types directly
● Mutable, but without I/O
○ ???
● With I/O
○ ???
Immutable Classes
data JBigInt =
pure native java.math.BigInteger where
pure native new :: String -> JBigInt
pure native add :: JBigInt -> JBigInt
-> JBigInt
add3 :: JBigInt -> JBigInt -> JBigInt
-> JBigInt
add3 n1 n2 n3 = (n1.add n2).add n3
Immutable Classes
data JBigInt =
pure native java.math.BigInteger where
pure native new :: String -> JBigInt
pure native add :: JBigInt -> JBigInt
-> JBigInt
add3 :: JBigInt -> JBigInt -> JBigInt
-> JBigInt
add3 n1 n2 n3 = (n1.add n2).add n3
the identifier for Frege
Immutable Classes
data JBigInt =
pure native java.math.BigInteger where
pure native new :: String -> JBigInt
pure native add :: JBigInt -> JBigInt
-> JBigInt
add3 :: JBigInt -> JBigInt -> JBigInt
-> JBigInt
add3 n1 n2 n3 = (n1.add n2).add n3
“pure native”, if it’s immutable
Immutable Classes
data JBigInt =
pure native java.math.BigInteger where
pure native new :: String -> JBigInt
pure native add :: JBigInt -> JBigInt
-> JBigInt
add3 :: JBigInt -> JBigInt -> JBigInt
-> JBigInt
add3 n1 n2 n3 = (n1.add n2).add n3
the FQCN in Java
Immutable Classes
data JBigInt =
pure native java.math.BigInteger where
pure native new :: String -> JBigInt
pure native add :: JBigInt -> JBigInt
-> JBigInt
add3 :: JBigInt -> JBigInt -> JBigInt
-> JBigInt
add3 n1 n2 n3 = (n1.add n2).add n3
the constructor
Immutable Classes
data JBigInt =
pure native java.math.BigInteger where
pure native new :: String -> JBigInt
pure native add :: JBigInt -> JBigInt
-> JBigInt
add3 :: JBigInt -> JBigInt -> JBigInt
-> JBigInt
add3 n1 n2 n3 = (n1.add n2).add n3
BigInteger#add in Java
Immutable Classes
data JBigInt =
pure native java.math.BigInteger where
pure native new :: String -> JBigInt
pure native add :: JBigInt -> JBigInt
-> JBigInt
add3 :: JBigInt -> JBigInt -> JBigInt
-> JBigInt
add3 n1 n2 n3 = (n1.add n2).add n3
invoke the method by dot-notations
“Levels” of Java’s Impurity
● Immutable
○ Maps to Frege’s data types directly
● Mutable, but without I/O
○ ???
● With I/O
○ Maps to IO monads
Classes with I/O
data JFReader =
mutable native java.io.FileReader where
native new :: String -> IO JFReader
native read :: JFReader -> IO Int
readOneFrom :: String -> IO Int
readOneFrom filename = do
fr <- JFReader.new filename
fr.read
Classes with I/O
data JFReader =
mutable native java.io.FileReader where
native new :: String -> IO JFReader
native read :: JFReader -> IO Int
readOneFrom :: String -> IO Int
readOneFrom filename = do
fr <- JFReader.new filename
fr.read
“mutable native”, if it acts on I/O
Classes with I/O
data JFReader =
mutable native java.io.FileReader where
native new :: String -> IO JFReader
native read :: JFReader -> IO Int
readOneFrom :: String -> IO Int
readOneFrom filename = do
fr <- JFReader.new filename
fr.read
the return values are in IO contexts
Classes with I/O
data JFReader =
mutable native java.io.FileReader where
native new :: String -> IO JFReader
native read :: JFReader -> IO Int
readOneFrom :: String -> IO Int
readOneFrom filename = do
fr <- JFReader.new filename
fr.read
use them as IO monads
“Levels” of Java’s Impurity
● Immutable
○ Maps to Frege’s data types directly
● Mutable, but without I/O
○ ???
● With I/O
○ Maps to IO monads
“Outwardly Pure” Methods
public String greeting(String name) {
StringBuilder sb =
new StringBuilder(“Hello, ”);
sb.append(name);
return sb.toString();
}
“Outwardly Pure” Methods
public String greeting(String name) {
StringBuilder sb =
new StringBuilder(“Hello, ”);
sb.append(name);
return sb.toString();
}
mutation (i.e. destructive updating)
“Outwardly Pure” Methods
public String greeting(String name) {
StringBuilder sb =
new StringBuilder(“Hello, ”);
sb.append(name);
return sb.toString();
}
but the return value is pure, though
Employ ST Monads!
“Levels” of Java’s Impurity
● Immutable
○ Maps to Frege’s data types directly
● Mutable, but without I/O
○ Maps to ST monads
● With I/O
○ Maps to IO monads
ST (State Transformer) Monads
● Encapsulates destructive mutations
● ST s TypeName
○ s represents ”unobservable” internal states
○ s must be a type variable
● We can retrieve pure values from the contexts
○ Unlike IO monads
Mutable Classes
data JBuilder =
native java.lang.StringBuilder where
native new :: String
-> ST s (Mutable s JBuilder)
native append :: Mutable s JBuilder
-> String
-> ST s (Mutable s JBuilder)
Mutable Classes
data JBuilder =
native java.lang.StringBuilder where
native new :: String
-> ST s (Mutable s JBuilder)
native append :: Mutable s JBuilder
-> String
-> ST s (Mutable s JBuilder)
“native”, if it has no I/O effects
Mutable Classes
data JBuilder =
native java.lang.StringBuilder where
native new :: String
-> ST s (Mutable s JBuilder)
native append :: Mutable s JBuilder
-> String
-> ST s (Mutable s JBuilder)
“unobservable” states
Mutable Classes
data JBuilder =
native java.lang.StringBuilder where
native new :: String
-> ST s (Mutable s JBuilder)
native append :: Mutable s JBuilder
-> String
-> ST s (Mutable s JBuilder)
wrap the values in “Mutable s”
Mutable Classes
data JBuilder =
native java.lang.StringBuilder where
native new :: String
-> ST s (Mutable s JBuilder)
native append :: Mutable s JBuilder
-> String
-> ST s (Mutable s JBuilder)
the return values are in ST contexts
Mutable Classes
greeting :: String -> ST s String
greeting name = do
sb <- JBuilder.new “Hello, ”
sb.append name
sb.toString
pureFunc :: String -> String
pureFunc name = (greeting name).run
Mutable Classes
greeting :: String -> ST s String
greeting name = do
sb <- JBuilder.new “Hello, ”
sb.append name
sb.toString
pureFunc :: String -> String
pureFunc name = (greeting name).run
use them as ST monads
Mutable Classes
greeting :: String -> ST s String
greeting name = do
sb <- JBuilder.new “Hello, ”
sb.append name
sb.toString
pureFunc :: String -> String
pureFunc name = (greeting name).run
“run” it to retrieve the pure value
Mutable Classes
greeting :: String -> ST s String
greeting name = do
sb <- JBuilder.new “Hello, ”
sb.append name
sb.toString
pureFunc :: String -> String
pureFunc name = (greeting name).run
we can regard it as a pure function
Summary
● Frege is the very Haskell for JVM
○ Syntax is just like Haskell’s
○ Pretty low learning cost for Haskellers
● Java interoperation with elegance
○ Compatible with the Haskell-like type system
○ Classify side-effects into pure, ST and IO
Have a Nice Frege Coding!
Presented by
CheshireCat (@y_taka_23)

Mais conteúdo relacionado

Mais procurados

The Sincerest Form of Flattery
The Sincerest Form of FlatteryThe Sincerest Form of Flattery
The Sincerest Form of FlatteryJosé Paumard
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)HamletDRC
 
Know your Javascript Engine
Know your Javascript EngineKnow your Javascript Engine
Know your Javascript Enginezipeng zhang
 
Kotlin in action
Kotlin in actionKotlin in action
Kotlin in actionCiro Rizzo
 
Java 8, Streams & Collectors, patterns, performances and parallelization
Java 8, Streams & Collectors, patterns, performances and parallelizationJava 8, Streams & Collectors, patterns, performances and parallelization
Java 8, Streams & Collectors, patterns, performances and parallelizationJosé Paumard
 
What’s new in Kotlin?
What’s new in Kotlin?What’s new in Kotlin?
What’s new in Kotlin?Squareboat
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Arnaud Giuliani
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsBartosz Kosarzycki
 
Frege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVMFrege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVMDierk König
 
The TclQuadcode Compiler
The TclQuadcode CompilerThe TclQuadcode Compiler
The TclQuadcode CompilerDonal Fellows
 
Introduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demoIntroduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demoMuhammad Abdullah
 
JDK8 : parallel programming made (too ?) easy
JDK8 : parallel programming made (too ?) easyJDK8 : parallel programming made (too ?) easy
JDK8 : parallel programming made (too ?) easyJosé Paumard
 
Kotlin 101 for Java Developers
Kotlin 101 for Java DevelopersKotlin 101 for Java Developers
Kotlin 101 for Java DevelopersChristoph Pickl
 
7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in KotlinLuca Guadagnini
 
Kotlin hands on - MorningTech ekito 2017
Kotlin hands on - MorningTech ekito 2017Kotlin hands on - MorningTech ekito 2017
Kotlin hands on - MorningTech ekito 2017Arnaud Giuliani
 
Java 8 Streams & Collectors : the Leuven edition
Java 8 Streams & Collectors : the Leuven editionJava 8 Streams & Collectors : the Leuven edition
Java 8 Streams & Collectors : the Leuven editionJosé Paumard
 
Java Keeps Throttling Up!
Java Keeps Throttling Up!Java Keeps Throttling Up!
Java Keeps Throttling Up!José Paumard
 

Mais procurados (20)

The Sincerest Form of Flattery
The Sincerest Form of FlatteryThe Sincerest Form of Flattery
The Sincerest Form of Flattery
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)
 
Know your Javascript Engine
Know your Javascript EngineKnow your Javascript Engine
Know your Javascript Engine
 
Kotlin in action
Kotlin in actionKotlin in action
Kotlin in action
 
Java 8, Streams & Collectors, patterns, performances and parallelization
Java 8, Streams & Collectors, patterns, performances and parallelizationJava 8, Streams & Collectors, patterns, performances and parallelization
Java 8, Streams & Collectors, patterns, performances and parallelization
 
What’s new in Kotlin?
What’s new in Kotlin?What’s new in Kotlin?
What’s new in Kotlin?
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
Frege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVMFrege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVM
 
The TclQuadcode Compiler
The TclQuadcode CompilerThe TclQuadcode Compiler
The TclQuadcode Compiler
 
Introduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demoIntroduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demo
 
Adventures in TclOO
Adventures in TclOOAdventures in TclOO
Adventures in TclOO
 
Kotlin wonderland
Kotlin wonderlandKotlin wonderland
Kotlin wonderland
 
JDK8 : parallel programming made (too ?) easy
JDK8 : parallel programming made (too ?) easyJDK8 : parallel programming made (too ?) easy
JDK8 : parallel programming made (too ?) easy
 
Kotlin 101 for Java Developers
Kotlin 101 for Java DevelopersKotlin 101 for Java Developers
Kotlin 101 for Java Developers
 
7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin
 
Kotlin hands on - MorningTech ekito 2017
Kotlin hands on - MorningTech ekito 2017Kotlin hands on - MorningTech ekito 2017
Kotlin hands on - MorningTech ekito 2017
 
Kotlin meets Gadsu
Kotlin meets GadsuKotlin meets Gadsu
Kotlin meets Gadsu
 
Java 8 Streams & Collectors : the Leuven edition
Java 8 Streams & Collectors : the Leuven editionJava 8 Streams & Collectors : the Leuven edition
Java 8 Streams & Collectors : the Leuven edition
 
Java Keeps Throttling Up!
Java Keeps Throttling Up!Java Keeps Throttling Up!
Java Keeps Throttling Up!
 

Destaque

Frege, What a Non-strict Language
Frege, What a Non-strict LanguageFrege, What a Non-strict Language
Frege, What a Non-strict Languagey_taka_23
 
猫でもわかる! モデル検査器 SPIN 入門
猫でもわかる! モデル検査器 SPIN 入門猫でもわかる! モデル検査器 SPIN 入門
猫でもわかる! モデル検査器 SPIN 入門y_taka_23
 
Fission で 始める Containerless Kubernetes #serverlesstokyo
Fission で 始める Containerless Kubernetes #serverlesstokyoFission で 始める Containerless Kubernetes #serverlesstokyo
Fission で 始める Containerless Kubernetes #serverlesstokyoy_taka_23
 
AWS は形式手法の夢を見るか? - モデル検査器 Alloy によるインフラ設計
AWS は形式手法の夢を見るか? - モデル検査器 Alloy によるインフラ設計AWS は形式手法の夢を見るか? - モデル検査器 Alloy によるインフラ設計
AWS は形式手法の夢を見るか? - モデル検査器 Alloy によるインフラ設計y_taka_23
 
Hello, Type Systems! - Introduction to Featherweight Java
Hello, Type Systems! - Introduction to Featherweight JavaHello, Type Systems! - Introduction to Featherweight Java
Hello, Type Systems! - Introduction to Featherweight Javay_taka_23
 
すごい Frege たのしく学ぼう!
すごい Frege たのしく学ぼう!すごい Frege たのしく学ぼう!
すごい Frege たのしく学ぼう!y_taka_23
 
机上の Kubernetes - 形式手法で見るコンテナオーケストレーション #NGK2016B
机上の Kubernetes -  形式手法で見るコンテナオーケストレーション #NGK2016B机上の Kubernetes -  形式手法で見るコンテナオーケストレーション #NGK2016B
机上の Kubernetes - 形式手法で見るコンテナオーケストレーション #NGK2016By_taka_23
 
形式手法と AWS のおいしい関係。- モデル検査器 Alloy によるインフラ設計技法 #jawsfesta
形式手法と AWS のおいしい関係。- モデル検査器 Alloy によるインフラ設計技法 #jawsfesta形式手法と AWS のおいしい関係。- モデル検査器 Alloy によるインフラ設計技法 #jawsfesta
形式手法と AWS のおいしい関係。- モデル検査器 Alloy によるインフラ設計技法 #jawsfestay_taka_23
 
形式手法で捗る!インフラ構成の設計と検証
形式手法で捗る!インフラ構成の設計と検証形式手法で捗る!インフラ構成の設計と検証
形式手法で捗る!インフラ構成の設計と検証y_taka_23
 
思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8
思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8
思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8y_taka_23
 

Destaque (10)

Frege, What a Non-strict Language
Frege, What a Non-strict LanguageFrege, What a Non-strict Language
Frege, What a Non-strict Language
 
猫でもわかる! モデル検査器 SPIN 入門
猫でもわかる! モデル検査器 SPIN 入門猫でもわかる! モデル検査器 SPIN 入門
猫でもわかる! モデル検査器 SPIN 入門
 
Fission で 始める Containerless Kubernetes #serverlesstokyo
Fission で 始める Containerless Kubernetes #serverlesstokyoFission で 始める Containerless Kubernetes #serverlesstokyo
Fission で 始める Containerless Kubernetes #serverlesstokyo
 
AWS は形式手法の夢を見るか? - モデル検査器 Alloy によるインフラ設計
AWS は形式手法の夢を見るか? - モデル検査器 Alloy によるインフラ設計AWS は形式手法の夢を見るか? - モデル検査器 Alloy によるインフラ設計
AWS は形式手法の夢を見るか? - モデル検査器 Alloy によるインフラ設計
 
Hello, Type Systems! - Introduction to Featherweight Java
Hello, Type Systems! - Introduction to Featherweight JavaHello, Type Systems! - Introduction to Featherweight Java
Hello, Type Systems! - Introduction to Featherweight Java
 
すごい Frege たのしく学ぼう!
すごい Frege たのしく学ぼう!すごい Frege たのしく学ぼう!
すごい Frege たのしく学ぼう!
 
机上の Kubernetes - 形式手法で見るコンテナオーケストレーション #NGK2016B
机上の Kubernetes -  形式手法で見るコンテナオーケストレーション #NGK2016B机上の Kubernetes -  形式手法で見るコンテナオーケストレーション #NGK2016B
机上の Kubernetes - 形式手法で見るコンテナオーケストレーション #NGK2016B
 
形式手法と AWS のおいしい関係。- モデル検査器 Alloy によるインフラ設計技法 #jawsfesta
形式手法と AWS のおいしい関係。- モデル検査器 Alloy によるインフラ設計技法 #jawsfesta形式手法と AWS のおいしい関係。- モデル検査器 Alloy によるインフラ設計技法 #jawsfesta
形式手法と AWS のおいしい関係。- モデル検査器 Alloy によるインフラ設計技法 #jawsfesta
 
形式手法で捗る!インフラ構成の設計と検証
形式手法で捗る!インフラ構成の設計と検証形式手法で捗る!インフラ構成の設計と検証
形式手法で捗る!インフラ構成の設計と検証
 
思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8
思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8
思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8
 

Semelhante a Learn You a Frege for Great Good!

Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018 Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018 Codemotion
 
Devnology Workshop Genpro 2 feb 2011
Devnology Workshop Genpro 2 feb 2011Devnology Workshop Genpro 2 feb 2011
Devnology Workshop Genpro 2 feb 2011Devnology
 
Madrid gug - sacando partido a las transformaciones ast de groovy
Madrid gug - sacando partido a las transformaciones ast de groovyMadrid gug - sacando partido a las transformaciones ast de groovy
Madrid gug - sacando partido a las transformaciones ast de groovyIván López Martín
 
Applets_Lab3Character Codes.jarMETA-INFMANIFEST.MFManife.docx
Applets_Lab3Character Codes.jarMETA-INFMANIFEST.MFManife.docxApplets_Lab3Character Codes.jarMETA-INFMANIFEST.MFManife.docx
Applets_Lab3Character Codes.jarMETA-INFMANIFEST.MFManife.docxarmitageclaire49
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvmArnaud Giuliani
 
G3 Summit 2016 - Taking Advantage of Groovy Annotations
G3 Summit 2016 - Taking Advantage of Groovy AnnotationsG3 Summit 2016 - Taking Advantage of Groovy Annotations
G3 Summit 2016 - Taking Advantage of Groovy AnnotationsIván López Martín
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)jeffz
 
Shiksharth com java_topics
Shiksharth com java_topicsShiksharth com java_topics
Shiksharth com java_topicsRajesh Verma
 
Programming Android Application in Scala.
Programming Android Application in Scala.Programming Android Application in Scala.
Programming Android Application in Scala.Brian Hsu
 
A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin XPeppers
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Cody Engel
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaSandesh Sharma
 
JVM Performance Magic Tricks
JVM Performance Magic TricksJVM Performance Magic Tricks
JVM Performance Magic TricksTakipi
 
Programmation fonctionnelle Scala
Programmation fonctionnelle ScalaProgrammation fonctionnelle Scala
Programmation fonctionnelle ScalaSlim Ouertani
 
Tour de Jackson: Forgotten Features of Jackson JSON processor
Tour de Jackson: Forgotten Features of Jackson JSON processorTour de Jackson: Forgotten Features of Jackson JSON processor
Tour de Jackson: Forgotten Features of Jackson JSON processorTatu Saloranta
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & AnswersRatnala Charan kumar
 
Greach 2015 AST – Groovy Transformers: More than meets the eye!
Greach 2015   AST – Groovy Transformers: More than meets the eye!Greach 2015   AST – Groovy Transformers: More than meets the eye!
Greach 2015 AST – Groovy Transformers: More than meets the eye!Iván López Martín
 

Semelhante a Learn You a Frege for Great Good! (20)

Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018 Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
 
Devnology Workshop Genpro 2 feb 2011
Devnology Workshop Genpro 2 feb 2011Devnology Workshop Genpro 2 feb 2011
Devnology Workshop Genpro 2 feb 2011
 
Madrid gug - sacando partido a las transformaciones ast de groovy
Madrid gug - sacando partido a las transformaciones ast de groovyMadrid gug - sacando partido a las transformaciones ast de groovy
Madrid gug - sacando partido a las transformaciones ast de groovy
 
Applets_Lab3Character Codes.jarMETA-INFMANIFEST.MFManife.docx
Applets_Lab3Character Codes.jarMETA-INFMANIFEST.MFManife.docxApplets_Lab3Character Codes.jarMETA-INFMANIFEST.MFManife.docx
Applets_Lab3Character Codes.jarMETA-INFMANIFEST.MFManife.docx
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvm
 
G3 Summit 2016 - Taking Advantage of Groovy Annotations
G3 Summit 2016 - Taking Advantage of Groovy AnnotationsG3 Summit 2016 - Taking Advantage of Groovy Annotations
G3 Summit 2016 - Taking Advantage of Groovy Annotations
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
 
Shiksharth com java_topics
Shiksharth com java_topicsShiksharth com java_topics
Shiksharth com java_topics
 
Programming Android Application in Scala.
Programming Android Application in Scala.Programming Android Application in Scala.
Programming Android Application in Scala.
 
A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin
 
Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)Privet Kotlin (Windy City DevFest)
Privet Kotlin (Windy City DevFest)
 
Ruby Classes
Ruby ClassesRuby Classes
Ruby Classes
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharma
 
Lua Study Share
Lua Study ShareLua Study Share
Lua Study Share
 
Groovy.pptx
Groovy.pptxGroovy.pptx
Groovy.pptx
 
JVM Performance Magic Tricks
JVM Performance Magic TricksJVM Performance Magic Tricks
JVM Performance Magic Tricks
 
Programmation fonctionnelle Scala
Programmation fonctionnelle ScalaProgrammation fonctionnelle Scala
Programmation fonctionnelle Scala
 
Tour de Jackson: Forgotten Features of Jackson JSON processor
Tour de Jackson: Forgotten Features of Jackson JSON processorTour de Jackson: Forgotten Features of Jackson JSON processor
Tour de Jackson: Forgotten Features of Jackson JSON processor
 
JavaScript(Es5) Interview Questions & Answers
JavaScript(Es5)  Interview Questions & AnswersJavaScript(Es5)  Interview Questions & Answers
JavaScript(Es5) Interview Questions & Answers
 
Greach 2015 AST – Groovy Transformers: More than meets the eye!
Greach 2015   AST – Groovy Transformers: More than meets the eye!Greach 2015   AST – Groovy Transformers: More than meets the eye!
Greach 2015 AST – Groovy Transformers: More than meets the eye!
 

Último

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Último (20)

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

Learn You a Frege for Great Good!

  • 1. Learn You a Frege for Great Good! Pure functional programming language for JVM CheshireCat (@y_taka_23) Tokyo Kabukiza.tech Meetup #9 (2016/03/20)
  • 2. Who am I? ● Name : CheshireCat ○ Twitter: @y_taka_23 ○ GitHub: y-taka-23 ● Favorites ○ Haskell ○ Formal methods (Coq, Alloy, SPIN etc...) ● (Would-be) Frege evangelist
  • 3. “Frege is a Haskell for JVM”
  • 4. Agenda ● What is Frege? ○ Basic features ○ Compatibility with Haskell ● Frege as a JVM language ○ How to deal the impurity ○ Java interoperation
  • 5. 1. What is Frege?
  • 6. Frege’s Essence ● Pure, non-strict functional language ● Strictly-typed, Hindley-Milner type inference ● Java interoperation with elegance
  • 7. “Hello, World” in Haskell module Hello where greeting :: String -> String greeting name = “Hello, ” ++ name main :: IO () main = do putStrLn $ greeting “World”
  • 8. “Hello, World” in Frege module Hello where greeting :: String -> String greeting name = “Hello, ” ++ name main :: [String] -> IO () main args = do putStrLn $ greeting “World”
  • 10. “Learn you a Haskell” Translation ● All example snipets into Frege ○ https://github.com/y-taka-23/learn-you-a-frege ● Compilable even in “dead-copied” translation
  • 11. Compatibility with Haskell ● Syntax, standard libs : almost compatible! ● Hard to use in “practical” Haskell ○ External dependencies ○ Most of GHC extensions ○ Template Haskell ● Java interoperation is necessary
  • 12. 2. Frege as a JVM Language
  • 13. Advantage of JVM Languages ● Platform-independent ○ Frege compiler generates Java source codes ● Feel free to invoke Java libraries ○ But pretty different regarding side-effects ■ Frege : Pure ■ Java : Impure, objects have own states
  • 14. Can we invoke Java in nicer way with Frege’s purity?
  • 15. “Levels” of Java’s Impurity ● Immutable ○ ??? ● Mutable, but without I/O ○ ??? ● With I/O ○ ???
  • 16. “Levels” of Java’s Impurity ● Immutable ○ Maps to Frege’s data types directly ● Mutable, but without I/O ○ ??? ● With I/O ○ ???
  • 17. Immutable Classes data JBigInt = pure native java.math.BigInteger where pure native new :: String -> JBigInt pure native add :: JBigInt -> JBigInt -> JBigInt add3 :: JBigInt -> JBigInt -> JBigInt -> JBigInt add3 n1 n2 n3 = (n1.add n2).add n3
  • 18. Immutable Classes data JBigInt = pure native java.math.BigInteger where pure native new :: String -> JBigInt pure native add :: JBigInt -> JBigInt -> JBigInt add3 :: JBigInt -> JBigInt -> JBigInt -> JBigInt add3 n1 n2 n3 = (n1.add n2).add n3 the identifier for Frege
  • 19. Immutable Classes data JBigInt = pure native java.math.BigInteger where pure native new :: String -> JBigInt pure native add :: JBigInt -> JBigInt -> JBigInt add3 :: JBigInt -> JBigInt -> JBigInt -> JBigInt add3 n1 n2 n3 = (n1.add n2).add n3 “pure native”, if it’s immutable
  • 20. Immutable Classes data JBigInt = pure native java.math.BigInteger where pure native new :: String -> JBigInt pure native add :: JBigInt -> JBigInt -> JBigInt add3 :: JBigInt -> JBigInt -> JBigInt -> JBigInt add3 n1 n2 n3 = (n1.add n2).add n3 the FQCN in Java
  • 21. Immutable Classes data JBigInt = pure native java.math.BigInteger where pure native new :: String -> JBigInt pure native add :: JBigInt -> JBigInt -> JBigInt add3 :: JBigInt -> JBigInt -> JBigInt -> JBigInt add3 n1 n2 n3 = (n1.add n2).add n3 the constructor
  • 22. Immutable Classes data JBigInt = pure native java.math.BigInteger where pure native new :: String -> JBigInt pure native add :: JBigInt -> JBigInt -> JBigInt add3 :: JBigInt -> JBigInt -> JBigInt -> JBigInt add3 n1 n2 n3 = (n1.add n2).add n3 BigInteger#add in Java
  • 23. Immutable Classes data JBigInt = pure native java.math.BigInteger where pure native new :: String -> JBigInt pure native add :: JBigInt -> JBigInt -> JBigInt add3 :: JBigInt -> JBigInt -> JBigInt -> JBigInt add3 n1 n2 n3 = (n1.add n2).add n3 invoke the method by dot-notations
  • 24. “Levels” of Java’s Impurity ● Immutable ○ Maps to Frege’s data types directly ● Mutable, but without I/O ○ ??? ● With I/O ○ Maps to IO monads
  • 25. Classes with I/O data JFReader = mutable native java.io.FileReader where native new :: String -> IO JFReader native read :: JFReader -> IO Int readOneFrom :: String -> IO Int readOneFrom filename = do fr <- JFReader.new filename fr.read
  • 26. Classes with I/O data JFReader = mutable native java.io.FileReader where native new :: String -> IO JFReader native read :: JFReader -> IO Int readOneFrom :: String -> IO Int readOneFrom filename = do fr <- JFReader.new filename fr.read “mutable native”, if it acts on I/O
  • 27. Classes with I/O data JFReader = mutable native java.io.FileReader where native new :: String -> IO JFReader native read :: JFReader -> IO Int readOneFrom :: String -> IO Int readOneFrom filename = do fr <- JFReader.new filename fr.read the return values are in IO contexts
  • 28. Classes with I/O data JFReader = mutable native java.io.FileReader where native new :: String -> IO JFReader native read :: JFReader -> IO Int readOneFrom :: String -> IO Int readOneFrom filename = do fr <- JFReader.new filename fr.read use them as IO monads
  • 29. “Levels” of Java’s Impurity ● Immutable ○ Maps to Frege’s data types directly ● Mutable, but without I/O ○ ??? ● With I/O ○ Maps to IO monads
  • 30. “Outwardly Pure” Methods public String greeting(String name) { StringBuilder sb = new StringBuilder(“Hello, ”); sb.append(name); return sb.toString(); }
  • 31. “Outwardly Pure” Methods public String greeting(String name) { StringBuilder sb = new StringBuilder(“Hello, ”); sb.append(name); return sb.toString(); } mutation (i.e. destructive updating)
  • 32. “Outwardly Pure” Methods public String greeting(String name) { StringBuilder sb = new StringBuilder(“Hello, ”); sb.append(name); return sb.toString(); } but the return value is pure, though
  • 34. “Levels” of Java’s Impurity ● Immutable ○ Maps to Frege’s data types directly ● Mutable, but without I/O ○ Maps to ST monads ● With I/O ○ Maps to IO monads
  • 35. ST (State Transformer) Monads ● Encapsulates destructive mutations ● ST s TypeName ○ s represents ”unobservable” internal states ○ s must be a type variable ● We can retrieve pure values from the contexts ○ Unlike IO monads
  • 36. Mutable Classes data JBuilder = native java.lang.StringBuilder where native new :: String -> ST s (Mutable s JBuilder) native append :: Mutable s JBuilder -> String -> ST s (Mutable s JBuilder)
  • 37. Mutable Classes data JBuilder = native java.lang.StringBuilder where native new :: String -> ST s (Mutable s JBuilder) native append :: Mutable s JBuilder -> String -> ST s (Mutable s JBuilder) “native”, if it has no I/O effects
  • 38. Mutable Classes data JBuilder = native java.lang.StringBuilder where native new :: String -> ST s (Mutable s JBuilder) native append :: Mutable s JBuilder -> String -> ST s (Mutable s JBuilder) “unobservable” states
  • 39. Mutable Classes data JBuilder = native java.lang.StringBuilder where native new :: String -> ST s (Mutable s JBuilder) native append :: Mutable s JBuilder -> String -> ST s (Mutable s JBuilder) wrap the values in “Mutable s”
  • 40. Mutable Classes data JBuilder = native java.lang.StringBuilder where native new :: String -> ST s (Mutable s JBuilder) native append :: Mutable s JBuilder -> String -> ST s (Mutable s JBuilder) the return values are in ST contexts
  • 41. Mutable Classes greeting :: String -> ST s String greeting name = do sb <- JBuilder.new “Hello, ” sb.append name sb.toString pureFunc :: String -> String pureFunc name = (greeting name).run
  • 42. Mutable Classes greeting :: String -> ST s String greeting name = do sb <- JBuilder.new “Hello, ” sb.append name sb.toString pureFunc :: String -> String pureFunc name = (greeting name).run use them as ST monads
  • 43. Mutable Classes greeting :: String -> ST s String greeting name = do sb <- JBuilder.new “Hello, ” sb.append name sb.toString pureFunc :: String -> String pureFunc name = (greeting name).run “run” it to retrieve the pure value
  • 44. Mutable Classes greeting :: String -> ST s String greeting name = do sb <- JBuilder.new “Hello, ” sb.append name sb.toString pureFunc :: String -> String pureFunc name = (greeting name).run we can regard it as a pure function
  • 45. Summary ● Frege is the very Haskell for JVM ○ Syntax is just like Haskell’s ○ Pretty low learning cost for Haskellers ● Java interoperation with elegance ○ Compatible with the Haskell-like type system ○ Classify side-effects into pure, ST and IO
  • 46. Have a Nice Frege Coding! Presented by CheshireCat (@y_taka_23)