Tagless Final Encoding - Algebras and Interpreters and also Programs - An introduction, through the work of Gabriel Volpe.
Slide deck home: http://fpilluminated.com/assets/tagless-final-encoding-algebras-interpreters-and-programs.html
Algebraic Thinking for Evolution of Pure Functional Domain ModelsDebasish Ghosh
The focus of the talk is to emphasize the importance of algebraic thinking when designing pure functional domain models. The talk begins with the definition of an algebra as consisting of a carrier type, a set of operations/functions and a set of laws on those operations. Using examples from the standard library, the talk shows how thinking of abstractions in terms of its algebra is more intuitive than discussing its operational semantics. The talk also discusses the virtues of parametricity and compositionality in designing proper algebras.
Algebras are compositional and help build larger algebras out of smaller ones. We start with base level types available in standard libraries and compose larger programs out of them. We take a real life use case for a domain model and illustrate how we can define the entire model using the power of algebraic composition of the various types. We talk about how to model side-effects as pure abstractions using algebraic effects. At no point we will talk about implementations.
At the end of the talk we will have a working model built completely out of the underlying algebra of the domain language.
Functional Domain Modeling - The ZIO 2 WayDebasish Ghosh
Principled way to design and implement functional domain models using some of the patterns of domain driven design. DDD, as the name suggests, is focused towards the domain model and the patterns of architecture that it encourages are also based on how we think of interactions amongst the basic abstractions of the domain. Of course the primary goal of the talk is to discuss how Scala and Zio 2 can be a potent combination in realizing the implementation of such models. This is not a talk on FP, the focus will be on how to structure and modularise an application based on some of the patterns of DDD.
Left and Right Folds- Comparison of a mathematical definition and a programm...Philip Schwarz
We compare typical definitions of the left and right fold functions, with their mathematical definitions in Sergei Winitzki’s upcoming book: The Science of Functional Programming.
Errata:
Slide 13: "The way 𝑓𝑜𝑙𝑑𝑙 does it is by associating to the right" - should, of course ,end in "to the left".
Algebraic Thinking for Evolution of Pure Functional Domain ModelsDebasish Ghosh
The focus of the talk is to emphasize the importance of algebraic thinking when designing pure functional domain models. The talk begins with the definition of an algebra as consisting of a carrier type, a set of operations/functions and a set of laws on those operations. Using examples from the standard library, the talk shows how thinking of abstractions in terms of its algebra is more intuitive than discussing its operational semantics. The talk also discusses the virtues of parametricity and compositionality in designing proper algebras.
Algebras are compositional and help build larger algebras out of smaller ones. We start with base level types available in standard libraries and compose larger programs out of them. We take a real life use case for a domain model and illustrate how we can define the entire model using the power of algebraic composition of the various types. We talk about how to model side-effects as pure abstractions using algebraic effects. At no point we will talk about implementations.
At the end of the talk we will have a working model built completely out of the underlying algebra of the domain language.
Functional Domain Modeling - The ZIO 2 WayDebasish Ghosh
Principled way to design and implement functional domain models using some of the patterns of domain driven design. DDD, as the name suggests, is focused towards the domain model and the patterns of architecture that it encourages are also based on how we think of interactions amongst the basic abstractions of the domain. Of course the primary goal of the talk is to discuss how Scala and Zio 2 can be a potent combination in realizing the implementation of such models. This is not a talk on FP, the focus will be on how to structure and modularise an application based on some of the patterns of DDD.
Left and Right Folds- Comparison of a mathematical definition and a programm...Philip Schwarz
We compare typical definitions of the left and right fold functions, with their mathematical definitions in Sergei Winitzki’s upcoming book: The Science of Functional Programming.
Errata:
Slide 13: "The way 𝑓𝑜𝑙𝑑𝑙 does it is by associating to the right" - should, of course ,end in "to the left".
Point free or die - tacit programming in Haskell and beyondPhilip Schwarz
I really liked Amar Shah's talk on point-free style as a tool for producing tacit code which communicates better because it is quiet and so easier to understand. https://www.youtube.com/watch?v=seVSlKazsNk
This slide deck is my effort to capture the content of the talk in a way that can aid its consumption, digestion and retention.
Download for better quality.
The Functional Programming Triad of Map, Filter and FoldPhilip Schwarz
This slide deck is my homage to SICP, the book which first introduced me to the Functional Programming triad of map, filter and fold.
It was during my Computer Science degree that a fellow student gave me a copy of the first edition, not long after the book came out.
I have not yet come across a better introduction to these three functions.
The upcoming slides are closely based on the second edition of the book, a free online copy of which can be found here:
https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book.html.
Download for original image quality.
Errata:
slide 20: the Clojure map function is in fact the Scheme one repeated - see code below for correction.
Scheme code: https://github.com/philipschwarz/the-fp-triad-of-map-filter-and-fold-scheme
Clojure code: https://github.com/philipschwarz/the-fp-triad-of-map-filter-and-fold-clojure
A short introduction to Apache Hadoop Hive, what is it and what can it do. How could we use it to connect a Hadoop cluster to business intelligence tools. Then create management reports from our Hadoop cluster data.
‘go-to’ general-purpose sequential collections -from Java To ScalaPhilip Schwarz
The simple idea of this slide deck is that it collects in a single place quite a bit of information that can be used to gain a basic understanding of some key differences between the ’goto’ sequential collections of Java and Scala.
Errata:
* the twitter handle of Daniel Westheide is @kaffeecoder and not @cafeecoder
* on slide 35, the numbers 215, 220, 225 and 230, should be 2^15, 2^20, 2^25 and 2^30 respectively
* on slide 54, the bottom left node should be green rather than black
If SQL is the universal language of data, why do we author our most important data applications (metrics, analytics, business intelligence) in languages other than SQL? Multidimensional databases and languages such as MDX, DAX and Tableau LOD solve these problems but introduce others: they require specialized knowledge, complicate the data pipeline and don’t integrate well. Is it possible to define and query business intelligence models in SQL?
Apache Calcite has extended SQL to support measures, evaluation context, and multidimensional expressions. With these concepts you can define data models that contain measures, use them in queries, and define new measures in queries.
A talk given by Julian Hyde to Apache Calcite's virtual meetup, 2023-03-15.
Javascript Prototypal Inheritance - Big PictureManish Jangir
Are you still confused about what the prototypes really are in Javascript. Read the slides from the very begining, you will have a very clear picture about inheritance in Javascript. If you have any questions, please leave a comment. I will try to clarify that thing.
download for better quality - Learn how to use an Applicative Functor to handle multiple independent effectful values through the work of Sergei Winitzki, Runar Bjarnason, Paul Chiusano, Debasish Ghosh and Adelbert Chang
Sharing code in between react components by using render props. HOC and react prop are some of the best ways to share code in react class components.
#hoc #react #renderprop
Java modular extension for operator overloadingijpla
The paper introduces a modular extension (plugin) for Java language compilers and Integrated Development Environments (IDE) which adds operator overloading feature to Java language while preserving backward compatibility.
The extension use the idea of library-based language extensibility similar to SugarJ[1]. But unlike most language extensions, it works directly inside the compiler and does not have any external preprocessors. This gives much faster compilation, better language compatibility and support of native developer tools (IDE, build tools).
The extension plugs into javac and Eclipse Java compilers as well as in all tools whose use the compilers such as IDEs (Netbeans, Eclipse, IntelliJ IDEA), build tools (ant, maven, gradle), etc. No compiler, IDE, build tools modification needed. Just add a jar library to classpath and/or install a plugin to your IDE.
The paper also discuss on how to build such Java compiler extensions.
The extension source code is open on
http://amelentev.github.io/java-oo/
Point free or die - tacit programming in Haskell and beyondPhilip Schwarz
I really liked Amar Shah's talk on point-free style as a tool for producing tacit code which communicates better because it is quiet and so easier to understand. https://www.youtube.com/watch?v=seVSlKazsNk
This slide deck is my effort to capture the content of the talk in a way that can aid its consumption, digestion and retention.
Download for better quality.
The Functional Programming Triad of Map, Filter and FoldPhilip Schwarz
This slide deck is my homage to SICP, the book which first introduced me to the Functional Programming triad of map, filter and fold.
It was during my Computer Science degree that a fellow student gave me a copy of the first edition, not long after the book came out.
I have not yet come across a better introduction to these three functions.
The upcoming slides are closely based on the second edition of the book, a free online copy of which can be found here:
https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book.html.
Download for original image quality.
Errata:
slide 20: the Clojure map function is in fact the Scheme one repeated - see code below for correction.
Scheme code: https://github.com/philipschwarz/the-fp-triad-of-map-filter-and-fold-scheme
Clojure code: https://github.com/philipschwarz/the-fp-triad-of-map-filter-and-fold-clojure
A short introduction to Apache Hadoop Hive, what is it and what can it do. How could we use it to connect a Hadoop cluster to business intelligence tools. Then create management reports from our Hadoop cluster data.
‘go-to’ general-purpose sequential collections -from Java To ScalaPhilip Schwarz
The simple idea of this slide deck is that it collects in a single place quite a bit of information that can be used to gain a basic understanding of some key differences between the ’goto’ sequential collections of Java and Scala.
Errata:
* the twitter handle of Daniel Westheide is @kaffeecoder and not @cafeecoder
* on slide 35, the numbers 215, 220, 225 and 230, should be 2^15, 2^20, 2^25 and 2^30 respectively
* on slide 54, the bottom left node should be green rather than black
If SQL is the universal language of data, why do we author our most important data applications (metrics, analytics, business intelligence) in languages other than SQL? Multidimensional databases and languages such as MDX, DAX and Tableau LOD solve these problems but introduce others: they require specialized knowledge, complicate the data pipeline and don’t integrate well. Is it possible to define and query business intelligence models in SQL?
Apache Calcite has extended SQL to support measures, evaluation context, and multidimensional expressions. With these concepts you can define data models that contain measures, use them in queries, and define new measures in queries.
A talk given by Julian Hyde to Apache Calcite's virtual meetup, 2023-03-15.
Javascript Prototypal Inheritance - Big PictureManish Jangir
Are you still confused about what the prototypes really are in Javascript. Read the slides from the very begining, you will have a very clear picture about inheritance in Javascript. If you have any questions, please leave a comment. I will try to clarify that thing.
download for better quality - Learn how to use an Applicative Functor to handle multiple independent effectful values through the work of Sergei Winitzki, Runar Bjarnason, Paul Chiusano, Debasish Ghosh and Adelbert Chang
Sharing code in between react components by using render props. HOC and react prop are some of the best ways to share code in react class components.
#hoc #react #renderprop
Java modular extension for operator overloadingijpla
The paper introduces a modular extension (plugin) for Java language compilers and Integrated Development Environments (IDE) which adds operator overloading feature to Java language while preserving backward compatibility.
The extension use the idea of library-based language extensibility similar to SugarJ[1]. But unlike most language extensions, it works directly inside the compiler and does not have any external preprocessors. This gives much faster compilation, better language compatibility and support of native developer tools (IDE, build tools).
The extension plugs into javac and Eclipse Java compilers as well as in all tools whose use the compilers such as IDEs (Netbeans, Eclipse, IntelliJ IDEA), build tools (ant, maven, gradle), etc. No compiler, IDE, build tools modification needed. Just add a jar library to classpath and/or install a plugin to your IDE.
The paper also discuss on how to build such Java compiler extensions.
The extension source code is open on
http://amelentev.github.io/java-oo/
A function is a group of statements that together perform a task. Every C program has at least one function, which is main(), and all the most trivial programs can define additional functions. You can divide up your code into separate functions.
LESSON 4: INTRODUCING FUNCTIONS AND MODULAR DESIGN
Learn about Functions in Python. Advantages and disadvantages of functions. Introduction to Modular design. Local and Global Variables and their use. Passing parameters. What are arguments? Big questions: Evolution vs Intelligent design in light of functions (and modular design). A closer look at Robotics and advances in this field. Challenges and tasks including with solutions. Suggested research/HW and YouTube video recommendations. A note on Python’s built in functions.
Similar to Tagless Final Encoding - Algebras and Interpreters and also Programs (20)
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidPhilip Schwarz
The subject of this deck is the small Print[A] program in the following blog post by Noel Welsh: https://www.inner-product.com/posts/direct-style-effects/.
Keywords: "direct-style", "context function", "context functions", "algebraic effect", "algebraic effects", "scala", "effect system", "effect systems", "effect", "side effect", "composition", "fp", "functional programming"
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
For functions that can be defined both as an instance of a right fold and as an instance of a left fold, one may be more efficient than the other.
Let's look at the example of a function 'decimal' that converts a list of digits into the corresponding decimal number.
Erratum: it has been pointed out that it is possible to define the zip function using a right fold (see slide 5).
A sighting of traverseFilter and foldMap in Practical FP in ScalaPhilip Schwarz
Slide deck home: http://fpilluminated.com/assets/sighting-of-scala-cats-traverseFilter-and-foldMap-in-practical-fp-in-scala.html.
Download PDF for perfect image quality.
A sighting of sequence function in Practical FP in ScalaPhilip Schwarz
Slide deck home: http://fpilluminated.com/assets/sighting-of-scala-cats-sequence-function-in-practical-fp-in-scala.html.
Download PDF for perfect image quality.
This talk was presented on Aug 3rd 2023 during the Scala in the City event a ITV in London https://www.meetup.com/scala-in-the-city/events/292844968/
Visit the following for a description, slideshow, all slides with transcript, pdf, github repo, and eventually a video recording: http://fpilluminated.com/assets/n-queens-combinatorial-puzzle-meets-cats.html
At the centre of this talk is the N-Queens combinatorial puzzle. The reason why this puzzle features in the Scala book and functional programming course by Martin Odersky (the language’s creator), is that such puzzles are a particularly suitable application area of 'for comprehensions'.
We’ll start by (re)acquainting ourselves with the puzzle, and seeing the role played in it by permutations. Next, we’ll see how, when wanting to visualise candidate puzzle solutions, Cats’ monoidal functions fold and foldMap are a great fit for combining images.
While we are all very familiar with the triad providing the bread, butter and jam of functional programming, i.e. map, filter and fold, not everyone knows about the corresponding functions in Cats’ monadic variant of the triad, i.e. mapM, filterM and foldM, which we are going to learn about next.
As is often the case in functional programming, the traverse function makes an appearance, and we shall grab the opportunity to point out the symmetry that exists in the interrelation of flatMap / foldMap / traverse and flatten / fold / sequence.
Armed with an understanding of foldM, we then look at how such a function can be used to implement an iterative algorithm for the N-Queens puzzle.
The talk ends by pointing out that the iterative algorithm is smarter than the recursive one, because it ‘remembers’ where it has already placed previous queens.
Kleisli composition, flatMap, join, map, unit - implementation and interrelat...Philip Schwarz
Kleisli composition, flatMap, join, map, unit. A study/memory aid, to help learn/recall their implementation/interrelation.
Version 2, updated for Scala 3
Nat, List and Option Monoids -from scratch -Combining and Folding -an examplePhilip Schwarz
Nat, List and Option Monoids, from scratch. Combining and Folding: an example.
This is a new version of the original which has some cosmetic changes and a new 7th slide which only differs from slide 6 in that it defines the fold function in terms of the foldRight function.
Code: https://github.com/philipschwarz/nat-list-and-option-monoids-from-scratch-combining-and-folding-an-example
Nat, List and Option Monoids -from scratch -Combining and Folding -an examplePhilip Schwarz
Nat, List and Option Monoids, from scratch. Combining and Folding: an example.
Code: https://github.com/philipschwarz/nat-list-and-option-monoids-from-scratch-combining-and-folding-an-example
The Sieve of Eratosthenes - Part II - Genuine versus Unfaithful Sieve - Haske...Philip Schwarz
When I posted the deck for Part 1 to the Scala users forum, Odd Möller linked to a paper titled "The Genuine Sieve of Eratosthenes", which speaks of the Unfaithful Sieve.
Part 2 is based on that paper and on Richard Bird's faithful Haskell implementation of the Sieve, which we translate into Scala.
Scala code for Richard Bird's infinite primes Haskell program: https://github.com/philipschwarz/sieve-of-eratosthenes-part-2-scala
Sum and Product Types -The Fruit Salad & Fruit Snack Example - From F# to Ha...Philip Schwarz
Sum and Product Types -The Fruit Salad & Fruit Snack Example - From F# to Haskell, Scala and Java.
Inspired by the example in Scott Wlaschin’s F# book: Domain Modeling Made Functional.
Download for better results.
Java 19 Code: https://github.com/philipschwarz/fruit-salad-and-fruit-snack-ADT-example-java
Jordan Peterson - The pursuit of meaning and related ethical axiomsPhilip Schwarz
I have only recently become aware of the work of Jordan Peterson. Because I am finding it so interesting, I hope that the following small collection of excerpts from some of his writings and speeches might entice any fellow latecomers to find out more about his work. See below for my own summary of some of the subjects touched upon in these slides.
Download for best results.
Defining filter using (a) recursion (b) folding (c) folding with S, B and I c...Philip Schwarz
Defining filter using
(a) recursion
(b) folding
(c) folding with S, B and I combinators
(d) folding with applicative functor and identity function.pdf
This second version adds a simpler folding definition, which I had left out in the first version.
The Sieve of Eratosthenes - Part 1 - with minor correctionsPhilip Schwarz
In this slide deck we are going to see some examples of how the effort required to read an understand the Sieve of Eratosthenes varies greatly depending on the programming paradigm used to implement the algorithm.
We'll see code in Java, Scheme, Haskell and Scala.
This version of the deck contains some minor corrections (see errata section in first version for details)
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus
As part of the DOE Integrated Research Infrastructure (IRI) program, NERSC at Lawrence Berkeley National Lab and ALCF at Argonne National Lab are working closely with General Atomics on accelerating the computing requirements of the DIII-D experiment. As part of the work the team is investigating ways to speedup the time to solution for many different parts of the DIII-D workflow including how they run jobs on HPC systems. One of these routes is looking at Globus Compute as a way to replace the current method for managing tasks and we describe a brief proof of concept showing how Globus Compute could help to schedule jobs and be a tool to connect compute at different facilities.
We describe the deployment and use of Globus Compute for remote computation. This content is aimed at researchers who wish to compute on remote resources using a unified programming interface, as well as system administrators who will deploy and operate Globus Compute services on their research computing infrastructure.
Software Engineering, Software Consulting, Tech Lead.
Spring Boot, Spring Cloud, Spring Core, Spring JDBC, Spring Security,
Spring Transaction, Spring MVC,
Log4j, REST/SOAP WEB-SERVICES.
Check out the webinar slides to learn more about how XfilesPro transforms Salesforce document management by leveraging its world-class applications. For more details, please connect with sales@xfilespro.com
If you want to watch the on-demand webinar, please click here: https://www.xfilespro.com/webinars/salesforce-document-management-2-0-smarter-faster-better/
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTier1 app
Even though at surface level ‘java.lang.OutOfMemoryError’ appears as one single error; underlyingly there are 9 types of OutOfMemoryError. Each type of OutOfMemoryError has different causes, diagnosis approaches and solutions. This session equips you with the knowledge, tools, and techniques needed to troubleshoot and conquer OutOfMemoryError in all its forms, ensuring smoother, more efficient Java applications.
First Steps with Globus Compute Multi-User EndpointsGlobus
In this presentation we will share our experiences around getting started with the Globus Compute multi-user endpoint. Working with the Pharmacology group at the University of Auckland, we have previously written an application using Globus Compute that can offload computationally expensive steps in the researcher's workflows, which they wish to manage from their familiar Windows environments, onto the NeSI (New Zealand eScience Infrastructure) cluster. Some of the challenges we have encountered were that each researcher had to set up and manage their own single-user globus compute endpoint and that the workloads had varying resource requirements (CPUs, memory and wall time) between different runs. We hope that the multi-user endpoint will help to address these challenges and share an update on our progress here.
Understanding Globus Data Transfers with NetSageGlobus
NetSage is an open privacy-aware network measurement, analysis, and visualization service designed to help end-users visualize and reason about large data transfers. NetSage traditionally has used a combination of passive measurements, including SNMP and flow data, as well as active measurements, mainly perfSONAR, to provide longitudinal network performance data visualization. It has been deployed by dozens of networks world wide, and is supported domestically by the Engagement and Performance Operations Center (EPOC), NSF #2328479. We have recently expanded the NetSage data sources to include logs for Globus data transfers, following the same privacy-preserving approach as for Flow data. Using the logs for the Texas Advanced Computing Center (TACC) as an example, this talk will walk through several different example use cases that NetSage can answer, including: Who is using Globus to share data with my institution, and what kind of performance are they able to achieve? How many transfers has Globus supported for us? Which sites are we sharing the most data with, and how is that changing over time? How is my site using Globus to move data internally, and what kind of performance do we see for those transfers? What percentage of data transfers at my institution used Globus, and how did the overall data transfer performance compare to the Globus users?
Enterprise Resource Planning System includes various modules that reduce any business's workload. Additionally, it organizes the workflows, which drives towards enhancing productivity. Here are a detailed explanation of the ERP modules. Going through the points will help you understand how the software is changing the work dynamics.
To know more details here: https://blogs.nyggs.com/nyggs/enterprise-resource-planning-erp-system-modules/
Into the Box Keynote Day 2: Unveiling amazing updates and announcements for modern CFML developers! Get ready for exciting releases and updates on Ortus tools and products. Stay tuned for cutting-edge innovations designed to boost your productivity.
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar
The European Union Agency for Law Enforcement Cooperation (Europol) has suffered an alleged data breach after a notorious threat actor claimed to have exfiltrated data from its systems. Infamous data leaker IntelBroker posted on the even more infamous BreachForums hacking forum, saying that Europol suffered a data breach this month.
The alleged breach affected Europol agencies CCSE, EC3, Europol Platform for Experts, Law Enforcement Forum, and SIRIUS. Infiltration of these entities can disrupt ongoing investigations and compromise sensitive intelligence shared among international law enforcement agencies.
However, this is neither the first nor the last activity of IntekBroker. We have compiled for you what happened in the last few days. To track such hacker activities on dark web sources like hacker forums, private Telegram channels, and other hidden platforms where cyber threats often originate, you can check SOCRadar’s Dark Web News.
Stay Informed on Threat Actors’ Activity on the Dark Web with SOCRadar!
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfJay Das
With the advent of artificial intelligence or AI tools, project management processes are undergoing a transformative shift. By using tools like ChatGPT, and Bard organizations can empower their leaders and managers to plan, execute, and monitor projects more effectively.
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Globus
The U.S. Geological Survey (USGS) has made substantial investments in meeting evolving scientific, technical, and policy driven demands on storing, managing, and delivering data. As these demands continue to grow in complexity and scale, the USGS must continue to explore innovative solutions to improve its management, curation, sharing, delivering, and preservation approaches for large-scale research data. Supporting these needs, the USGS has partnered with the University of Chicago-Globus to research and develop advanced repository components and workflows leveraging its current investment in Globus. The primary outcome of this partnership includes the development of a prototype enterprise repository, driven by USGS Data Release requirements, through exploration and implementation of the entire suite of the Globus platform offerings, including Globus Flow, Globus Auth, Globus Transfer, and Globus Search. This presentation will provide insights into this research partnership, introduce the unique requirements and challenges being addressed and provide relevant project progress.
Large Language Models and the End of ProgrammingMatt Welsh
Talk by Matt Welsh at Craft Conference 2024 on the impact that Large Language Models will have on the future of software development. In this talk, I discuss the ways in which LLMs will impact the software industry, from replacing human software developers with AI, to replacing conventional software with models that perform reasoning, computation, and problem-solving.
top nidhi software solution freedownloadvrstrong314
This presentation emphasizes the importance of data security and legal compliance for Nidhi companies in India. It highlights how online Nidhi software solutions, like Vector Nidhi Software, offer advanced features tailored to these needs. Key aspects include encryption, access controls, and audit trails to ensure data security. The software complies with regulatory guidelines from the MCA and RBI and adheres to Nidhi Rules, 2014. With customizable, user-friendly interfaces and real-time features, these Nidhi software solutions enhance efficiency, support growth, and provide exceptional member services. The presentation concludes with contact information for further inquiries.
Accelerate Enterprise Software Engineering with PlatformlessWSO2
Key takeaways:
Challenges of building platforms and the benefits of platformless.
Key principles of platformless, including API-first, cloud-native middleware, platform engineering, and developer experience.
How Choreo enables the platformless experience.
How key concepts like application architecture, domain-driven design, zero trust, and cell-based architecture are inherently a part of Choreo.
Demo of an end-to-end app built and deployed on Choreo.
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Shahin Sheidaei
Games are powerful teaching tools, fostering hands-on engagement and fun. But they require careful consideration to succeed. Join me to explore factors in running and selecting games, ensuring they serve as effective teaching tools. Learn to maintain focus on learning objectives while playing, and how to measure the ROI of gaming in education. Discover strategies for pitching gaming to leadership. This session offers insights, tips, and examples for coaches, team leads, and enterprise leaders seeking to teach from simple to complex concepts.
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Mind IT Systems
Healthcare providers often struggle with the complexities of chronic conditions and remote patient monitoring, as each patient requires personalized care and ongoing monitoring. Off-the-shelf solutions may not meet these diverse needs, leading to inefficiencies and gaps in care. It’s here, custom healthcare software offers a tailored solution, ensuring improved care and effectiveness.
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Tagless Final Encoding - Algebras and Interpreters and also Programs
1. Tagless Final Encoding
Algebras and Interpreters
and also Programs
an introduction, through the work of Gabriel Volpe
Algebras
Tagless Final
Encoding
@philip_schwarz
slides by http://fpilluminated.com/
2. This slide deck is a quick, introductory look, at Tagless Final, as explained (in rather more depth
than is possible or appropriate here) by Gabriel in his great book: Practical FP in Scala, a Hands-
on Approach.
In the first six slides, we are going to see Gabriel introduce the key elements of the technique.
Tagless final is all about algebras and interpreters. Yet,
something is missing when it comes to writing applications…
Tagless final is a great technique used to
structure purely functional applications.
Yes, as you’ll see, to the two official pillars of Tagless Final, i.e. algebras and interpreters, Gabriel
adds a third one: programs.
Algebras
Tagless Final
Encoding
@philip_schwarz
3. Algebras
An algebra describes a new language (DSL) within a host language, in this case, Scala.
This is a tagless final encoded algebra; tagless algebra, or algebra for short: a simple interface that
abstracts over the effect type using a type constructor F[_].
Do not confuse algebras with typeclasses, which in Scala, happen to share the same encoding.
The difference is that typeclasses should have coherent instances, whereas tagless algebras could have
many implementations, or more commonly called interpreters.
…
Overall, tagless algebras seem a perfect fit for encoding business concepts. For example, an algebra
responsible for managing items could be encoded as follows.
Nothing new, right? This tagless final encoded algebra is merely an interface that abstracts over the effect
type. Notice that neither the algebra nor its functions have any typeclass constraint.
If you find yourself needing to add a typeclass constraint, such as Monad, to your algebra, what you probably
need is a program.
The reason being that typeclass constraints define capabilities, which belong in programs and interpreters.
Algebras should remain completely abstract.
trait Items[F[_]] {
def getAll: F[List[Item]]
def add(item: Item): F[Unit]
}
trait Counter[F[_]] {
def increment: F[Unit]
def get: F[Int]
}
Tagless algebras should not have typeclass constraints
Tips
4. Interpreters
We would normally have two interpreters per algebra: one for testing and one for doing real things. For
instance, we could have two different implementations of our Counter.
A default interpreter using Redis.
And a test interpreter using an in-memory data structure.
Interpreters help us encapsulate state and allow separation of concerns: the interface knows nothing about
the implementation details. Moreover, interpreters can be written either using a concrete datatype such as
IO or going polymorphic all the way, as we did in this case.
object Counter {
@newtype case class RedisKey(value: String)
def make[F[_]: Functor](
key: RedisKey,
cmd: RedisCommands[F, String, Int]
): Counter[F] =
new Counter[F] {
def increment: F[Unit] =
cmd.increment(key.value).void
def get: F[Int] =
cmd.get(key.value).map(_.getOrElse(0))
}
}
def testCounter[F[_]](
ref: Ref[F, Int]
): Counter[F] = new Counter[F] {
def increment: F[Unit] = ref.update(_ + 1)
def get: F[Int] = ref.get
}
5. We are currently working our way through slides containing excerpts from Chapter 2: Tagless Final Encoding.
The next slide is an exception in that it contains an excerpt from Chapter1: Best Practices, which has already
introduced (in a less formal way), the concept of an interpreter for the Counter trait (without yet referring to
the latter as an algebra).
6. In-memory counter
Let’s say we need an in-memory counter that needs to be accessed and modified by other components. Here
is what our interface could look like.
It has a higher-kinded type F[_], representing an abstract effect, which most of the time ends up being IO,
but it could really be any other concrete type that fits the shape.
Next, we need to define an interpreter in the companion object of our interface, in this case using a Ref. We
will talk more about it in the next section.
…
Moving on, it’s worth highlighting that other programs will interact with this counter solely via its interface. E.g.
// prints out 0,1,6 when executed
def program(c: Counter[IO]): IO[Unit] =
for {
_ <- c.get.flatMap(IO.println)
_ <- c.increment
_ <- c.get.flatMap(IO.println)
_ <- c.increment.replicateA(5).void
_ <- c.get.flatMap(IO.println)
} yield ()
In the next chapter, we will discuss whether it is best to pass the dependency implicitly or explicitly.
object Counter {
def make[F[_]: Functor: Ref.Make]: F[Counter[F]] =
Ref.of[F, Int](0).map { ref =>
new Counter[F] {
def increment: F[Unit] = ref.update(_ + 1)
def get: F[Int] = ref.get
}
}
}
trait Counter[F[_]] {
def increment: F[Unit]
def get: F[Int]
}
import cats.Functor
import cats.effect.kernel.Ref
import cats.syntax.functor._
7. Programs
Tagless final is all about algebras and interpreters. Yet, something is missing when it comes to writing applications: we
need to use these algebras to describe business logic, and this logic belongs in what I like to call programs.
Although it is not an official name – and it is not mentioned in the original tagless final paper – it is how we will be
referring to such interfaces in this book.
Say we need to increase a counter every time there is a new item added. We could encode it as follows.
Observe the characteristics of this program. It is pure business logic, and it holds no state at all, which in any case,
must be encapsulated in the interpreters. Notice the typeclass constraints as well; it is a good practice to have them
in programs instead of tagless algebras.
…
Moreover, we can discuss typeclass constraints. In this case, we only need Apply to use *> (alias for productR).
However, it would also work with Applicative or Monad. The rule of thumb is to limit ourselves to adopt the least
powerful typeclass that gets the job done.
It is worth mentioning that Apply itself doesn’t specify the semantics of composition solely with this constraint, *>
might combine its arguments sequentially or parallelly, depending on the underlying typeclass instance. To ensure
our composition is sequential, we could use FlatMap instead of Apply.
class ItemsCounter[F[_]: Apply](
counter: Counter[F],
items: Items[F]
){
def addItem(item: Item): F[Unit] =
items.add(item) *>
counter.increment
}
Programs can make use of algebras and other programs
Notes
When adding a typeclass constraint, remember about the principle of least power
Tips
8. Other kinds of programs might be directly encoded as functions.
Furthermore, we could have programs composed of other programs.
Whether we encode programs in one way or another, they should describe pure business logic and nothing else.
The question is: what is pure business logic? We could try and define a set of rules to abide by. It is allowed to:
• Combine pure computations in terms of tagless algebras and programs.
– Only doing what our effect constraints allows us to do.
• Perform logging (or console stuff) only via a tagless algebra.
– In Chapter 8, we will see how to ignore logging or console stuff in tests, which are most of the time irrelevant in
such context.
You can use this as a reference. However, the answer should come up as a collective agreement within your team.
def program[F[_]: Console: Monad]: F[Unit] =
for {
_ <- Console[F].println("Enter your name: ")
n <- Console[F].readLine
_ <- Console[F].println(s"Hello $n!")
} yield ()
class MasterMind[F[_]: Console: Monad](
itemsCounter: ItemsCounter[F],
counter: Counter[F]
){
def logic(item: Item): F[Unit] =
for {
_ <- itemsCounter.addItem(item)
c <- counter.get
_ <- Console[F].println(s"Number of items: $c")
} yield ()
}
9. def program(counter: Counter[IO]): IO[Unit] =
for {
_ <- display(counter)
_ <- counter.increment
_ <- display(counter)
_ <- repeat(5){ counter.increment }
_ <- display(counter)
} yield ()
def display(counter: Counter[IO]): IO[Unit] =
counter.get.flatMap(IO.println)
def repeat(n: Int)(action: IO[Unit]): IO[Unit] =
action.replicateA(n).void
def program(c: Counter[IO]): IO[Unit] =
for {
_ <- c.get.flatMap(IO.println)
_ <- c.increment
_ <- c.get.flatMap(IO.println)
_ <- c.increment.replicateA(5).void
_ <- c.get.flatMap(IO.println)
} yield ()
REFACTOR
Let’s refactor a little bit the first program that we came across.
10. On the next slide, we are going to take that program and wrap it in a tiny application that can be executed.
We are also going to use a little bit of UML, to show how the program uses an algebra (i.e. an interface) implemented by an interpreter.
To do this, we are going to slightly abuse UML, along the lines described by Martin Fowler in https://martinfowler.com/bliki/BallAndSocket.html.
Program
Algebra
Interface Algebra is used (required) by Program.
Interface Algebra is realized (implemented) by Interpreter.
Interpreter
Algebra
Program Interpreter
Algebra
Interface Algebra, which is realized (implemented)
by Interpreter, is used (required) by Program.
Algebra
ball
Algebra interface.
In a further twist, I’ll also be putting Algebra inside the ball.
socket
mated socket and ball
valid UML notation
invalid
UML
notation
@philip_schwarz
12. Next, we take the mastermind program that we saw earlier, and
use it in a tiny application that tests it a bit.
Because we are going to need it in the next slide, here is a much
pared down version of the Item referenced by the program.
import io.estatico.newtype.macros.newtype
import java.util.UUID
object item {
@newtype case class ItemId(value: UUID)
@newtype case class ItemName(value: String)
@newtype case class ItemDescription(value: String)
case class Item(uuid: ItemId, name: ItemName, description: ItemDescription)
}
14. Of course this was just a quick introduction to the Tagless Final technique.
See the book for much more depth, and many other important aspects of using the technique.
The next slide contains just a taster.
15. Some might question the decision to invest in this technique for a business application, claiming it entails great complexity.
This is a fair concern but let’s ask ourselves, what’s the alternative? Using IO directly in the entire application? By all means,
this could work, but at what cost? At the very least, we would be giving up on parametricity† and the principle of least power.
There is a huge mix of concerns. How can we possibly
reason about this function? How can we even test it? We
got ourselves into a very uncomfortable situation.
Now let’s compare it against the abstract equivalent of
it. Instead of performing side-effects, we have now
typeclass constraints and capabilities.
Teams making use of this technique will immediately understand that all we can do in the body of the constrained function is to compose
Counter, Log, and Time actions sequentially as well as to use any property made available by the Monad constraint. It is true, however, that
the Scala compiler does not enforce it so this is up to the discipline of the team.
Since Scala is a hybrid language, the only thing stopping us from running wild side-effects in this function is self-discipline and peer reviews.
However, good practices are required in any team for multiple purposes, so I would argue it is not necessarily a bad thing, as we can do the same
thing in programs encoded directly in IO.
† https://en.wikipedia.org/wiki/Parametricity