SlideShare une entreprise Scribd logo
1  sur  14
Télécharger pour lire hors ligne
FLAVOUR OF M-
PROGRAMMING
WITH SHAPELESS
LETS COMPILER WRITE
CODE FOR US
...lets imagine that your program its just a data.
Meta programming is about:
META
FLAVOUROFM-PROGRAMMINGWITHSHAPELESS
flatMap
Exposing part of compiler outside
Code generation
Moving to compile time evaluation
SHAPELESS
FLAVOUROFM-PROGRAMMINGWITHSHAPELESS
Library that implements heterogeneous list and bunch of macroses for it
How we can store different types
of data in one data structure?
SHAPELESS
FLAVOUROFM-PROGRAMMINGWITHSHAPELESS
Library that implements heterogeneous list and bunch of macroses for it
List[Any]
List[AbstractClass]
HList
SHAPELESS
FLAVOUROFM-PROGRAMMINGWITHSHAPELESS
Library that implements heterogeneous list and bunch of macroses for it
HList - its infinite static typed list based on
abstract data types.
Its like tuple: (String, Int, Long, ...), but
without limit on amount of elements inside.
SHAPELESS
FLAVOUROFM-PROGRAMMINGWITHSHAPELESS
Library that implements heterogeneous list and bunch of macroses for it
HList example:
val list: String :: Int :: HNil =
"Word" :: 99 :: HNil
SHAPELESS
FLAVOUROFM-PROGRAMMINGWITHSHAPELESS
Library that implements heterogeneous list and bunch of macroses for it
What we can do with
String :: Int :: HNil type
Everything!
def transform(hList: HList.Repr): Seq[String]
SHAPELESS
FLAVOUROFM-PROGRAMMINGWITHSHAPELESS
Library that implements heterogeneous list and bunch of macroses for it
String :: Int :: HNil
HList[String, HList[Int, HNil]]
and we want achieve Seq[String]
Basic types transformers: Int => Seq[String]
Shapeless type transformer: HList[A, B] => Seq[String]
SHAPELESS
FLAVOUROFM-PROGRAMMINGWITHSHAPELESS
Library that implements heterogeneous list and bunch of macroses for it
trait Transformer[A] {
    def transform(a: A): Seq[String]
}
implicit val intT = new Transformer[Int] {
   def transform(a: Int): Seq[String] = Seq(a.toString)
 }
SHAPELESS
FLAVOUROFM-PROGRAMMINGWITHSHAPELESS
Library that implements heterogeneous list and bunch of macroses for it
// HList[String, HList[Int, HNil]]
implicit def hListT[H, T <: HList]
(implicit headT: Transformer[H],
             tailT: Transformer[T]): Transformer[H :: T] = ???
implicit val hNilT = new Transformer[HNil] {
   override def transform(a: HNil): Seq[String] = Nil
 }
SHAPELESS
FLAVOUROFM-PROGRAMMINGWITHSHAPELESS
Library that implements heterogeneous list and bunch of macroses for it
implicitly[Transformer[String :: Int :: Nil]].transform(ourHList)
Search for implicit to convert HList[A, B]
Build HList[String, HList[B, C]]
Search for implicit to convert String
Search for implicit to convert Int and Nil
Provide converter from HList[Int, Nil] to Seq[String]
Provide converter from HList[String, HList[Int, Nil]] to Seq!
USE CASE
FLAVOUROFM-PROGRAMMINGWITHSHAPELESS
case class User (
  name: String,
  age: Int
)
User("MyName", 99)
def serialize(user: User): String = ???
// "MyName, 99"
USE CASE
FLAVOUROFM-PROGRAMMINGWITHSHAPELESS
implicit val customerGen = Generic[Customer]
def createEncoder[A, R]
    (implicit gen: Generic.Aux[A, R],
     encoder: Transformer[R]): Transformer[A] =
   new Transformer[A] {
     override def transform(a: A) =
          encoder.encode(gen.to(a))
   }
THANKS!
TIME TO ARGUE

Contenu connexe

Tendances

Tendances (20)

Import Data using R
Import Data using R Import Data using R
Import Data using R
 
Hash table in java
Hash table in javaHash table in java
Hash table in java
 
Lambdas HOL
Lambdas HOLLambdas HOL
Lambdas HOL
 
(chapter 7) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 7) A Concise and Practical Introduction to Programming Algorithms in...(chapter 7) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 7) A Concise and Practical Introduction to Programming Algorithms in...
 
Applications of Stack in DSA
Applications of Stack in DSAApplications of Stack in DSA
Applications of Stack in DSA
 
Genomic Analysis in Scala
Genomic Analysis in ScalaGenomic Analysis in Scala
Genomic Analysis in Scala
 
Dax Declarative Api For Xml
Dax   Declarative Api For XmlDax   Declarative Api For Xml
Dax Declarative Api For Xml
 
Python - Lecture 12
Python - Lecture 12Python - Lecture 12
Python - Lecture 12
 
Pandas csv
Pandas csvPandas csv
Pandas csv
 
The List Data Model
The List Data ModelThe List Data Model
The List Data Model
 
Slides
SlidesSlides
Slides
 
Jug Marche: Meeting June 2014. Java 8 hands on
Jug Marche: Meeting June 2014. Java 8 hands onJug Marche: Meeting June 2014. Java 8 hands on
Jug Marche: Meeting June 2014. Java 8 hands on
 
Epic success \/ failure, refactoring to *real* FP
Epic success \/ failure, refactoring to *real* FPEpic success \/ failure, refactoring to *real* FP
Epic success \/ failure, refactoring to *real* FP
 
Skipl List implementation - Part 1
Skipl List implementation - Part 1Skipl List implementation - Part 1
Skipl List implementation - Part 1
 
(3) collections algorithms
(3) collections algorithms(3) collections algorithms
(3) collections algorithms
 
Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
 
Stack data structure in Data Structure using C
Stack data structure in Data Structure using C Stack data structure in Data Structure using C
Stack data structure in Data Structure using C
 
Stack c6
Stack c6Stack c6
Stack c6
 
ADVANCED FEATURES OF C++
ADVANCED FEATURES OF C++ADVANCED FEATURES OF C++
ADVANCED FEATURES OF C++
 
Mandatory sql functions for beginners
Mandatory sql functions for beginnersMandatory sql functions for beginners
Mandatory sql functions for beginners
 

En vedette

GRUPO INTERGUBERNAMENTAL DE EXPERTOS SOBRE CAMBIO CLIMÁTICO – IPCC GT III
GRUPO INTERGUBERNAMENTAL DE EXPERTOS SOBRE CAMBIO CLIMÁTICO – IPCC GT IIIGRUPO INTERGUBERNAMENTAL DE EXPERTOS SOBRE CAMBIO CLIMÁTICO – IPCC GT III
GRUPO INTERGUBERNAMENTAL DE EXPERTOS SOBRE CAMBIO CLIMÁTICO – IPCC GT III
ipcc-media
 

En vedette (16)

Webinaire sur l'innovation de production
Webinaire sur l'innovation de productionWebinaire sur l'innovation de production
Webinaire sur l'innovation de production
 
3Com SL-3055 (5 NEW IN BO
3Com SL-3055 (5 NEW IN BO3Com SL-3055 (5 NEW IN BO
3Com SL-3055 (5 NEW IN BO
 
Cloud digital life
Cloud digital life Cloud digital life
Cloud digital life
 
Geschäftspräsentation Synergy 2017
Geschäftspräsentation Synergy 2017Geschäftspräsentation Synergy 2017
Geschäftspräsentation Synergy 2017
 
Actividades urbanas
Actividades urbanasActividades urbanas
Actividades urbanas
 
Tieu chuan thiet ke nut giao thong
Tieu chuan thiet ke nut giao thongTieu chuan thiet ke nut giao thong
Tieu chuan thiet ke nut giao thong
 
Como consultar el saldo en tu tarjeta
Como consultar el saldo en tu tarjetaComo consultar el saldo en tu tarjeta
Como consultar el saldo en tu tarjeta
 
Investigación de incidentes
Investigación de incidentesInvestigación de incidentes
Investigación de incidentes
 
8 minutes of functional primitives
8 minutes of functional primitives8 minutes of functional primitives
8 minutes of functional primitives
 
Webinaire sur l'innovation dans la commercialisation
Webinaire sur l'innovation dans la commercialisationWebinaire sur l'innovation dans la commercialisation
Webinaire sur l'innovation dans la commercialisation
 
SERIES MAS VISTAS EN NETFLIX
SERIES MAS VISTAS EN NETFLIXSERIES MAS VISTAS EN NETFLIX
SERIES MAS VISTAS EN NETFLIX
 
Toma de decisiones
Toma de decisionesToma de decisiones
Toma de decisiones
 
Accidentes de trabajo causas, efectos y prevención. cesar eduardo jiménez cas...
Accidentes de trabajo causas, efectos y prevención. cesar eduardo jiménez cas...Accidentes de trabajo causas, efectos y prevención. cesar eduardo jiménez cas...
Accidentes de trabajo causas, efectos y prevención. cesar eduardo jiménez cas...
 
Manual de Motocicletas
Manual de MotocicletasManual de Motocicletas
Manual de Motocicletas
 
GRUPO INTERGUBERNAMENTAL DE EXPERTOS SOBRE CAMBIO CLIMÁTICO – IPCC GT III
GRUPO INTERGUBERNAMENTAL DE EXPERTOS SOBRE CAMBIO CLIMÁTICO – IPCC GT IIIGRUPO INTERGUBERNAMENTAL DE EXPERTOS SOBRE CAMBIO CLIMÁTICO – IPCC GT III
GRUPO INTERGUBERNAMENTAL DE EXPERTOS SOBRE CAMBIO CLIMÁTICO – IPCC GT III
 
Biblioteca virtual
Biblioteca virtualBiblioteca virtual
Biblioteca virtual
 

Similaire à Flavour of meta-programming with shapeless

you will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdfyou will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdf
info335653
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its function
Frankie Jones
 

Similaire à Flavour of meta-programming with shapeless (20)

Motivation and Mechanics behind some aspects of Shapeless
Motivation and Mechanics behind some aspects of ShapelessMotivation and Mechanics behind some aspects of Shapeless
Motivation and Mechanics behind some aspects of Shapeless
 
Shapeless- Generic programming for Scala
Shapeless- Generic programming for ScalaShapeless- Generic programming for Scala
Shapeless- Generic programming for Scala
 
Matlab Manual
Matlab ManualMatlab Manual
Matlab Manual
 
Functional programming seminar (haskell)
Functional programming seminar (haskell)Functional programming seminar (haskell)
Functional programming seminar (haskell)
 
Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2
 
Scala collections api expressivity and brevity upgrade from java
Scala collections api  expressivity and brevity upgrade from javaScala collections api  expressivity and brevity upgrade from java
Scala collections api expressivity and brevity upgrade from java
 
Python Programming Basics for begginners
Python Programming Basics for begginnersPython Programming Basics for begginners
Python Programming Basics for begginners
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
 
LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To Lisp
 
The Style of C++ 11
The Style of C++ 11The Style of C++ 11
The Style of C++ 11
 
you will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdfyou will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdf
 
Charles Sharp: Java 8 Streams
Charles Sharp: Java 8 StreamsCharles Sharp: Java 8 Streams
Charles Sharp: Java 8 Streams
 
Introduction to Apache HBase, MapR Tables and Security
Introduction to Apache HBase, MapR Tables and SecurityIntroduction to Apache HBase, MapR Tables and Security
Introduction to Apache HBase, MapR Tables and Security
 
Functional Programming in Java 8 - Lambdas and Streams
Functional Programming in Java 8 - Lambdas and StreamsFunctional Programming in Java 8 - Lambdas and Streams
Functional Programming in Java 8 - Lambdas and Streams
 
Mysql1
Mysql1Mysql1
Mysql1
 
Real World Generics In Swift
Real World Generics In SwiftReal World Generics In Swift
Real World Generics In Swift
 
Type header file in c++ and its function
Type header file in c++ and its functionType header file in c++ and its function
Type header file in c++ and its function
 
Btech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsBtech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and strings
 
Functions torage class and array and strings-
Functions torage class and array and strings-Functions torage class and array and strings-
Functions torage class and array and strings-
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 

Dernier

FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 

Dernier (20)

FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 

Flavour of meta-programming with shapeless