What does "free", as in "free monad" mean? How can a free structure be constructed? How does this construction relate to the definition of free found in Scalaz/Cats/Haskell?
How to construct a free object for any syntax? Going through universal algebra, term algebras, free monoids and free monads. Presented at LambdaConf 2017
Monads and Monoids: from daily java to Big Data analytics in Scala
Finally, after two decades of evolution, Java 8 made a step towards functional programming. What can Java learn from other mature functional languages? How to leverage obscure mathematical abstractions such as Monad or Monoid in practice? Usually people find it scary and difficult to understand. Oleksiy will explain these concepts in simple words to give a feeling of powerful tool applicable in many domains, from daily Java and Scala routines to Big Data analytics with Storm or Hadoop.
How to construct a free object for any syntax? Going through universal algebra, term algebras, free monoids and free monads. Presented at LambdaConf 2017
Monads and Monoids: from daily java to Big Data analytics in Scala
Finally, after two decades of evolution, Java 8 made a step towards functional programming. What can Java learn from other mature functional languages? How to leverage obscure mathematical abstractions such as Monad or Monoid in practice? Usually people find it scary and difficult to understand. Oleksiy will explain these concepts in simple words to give a feeling of powerful tool applicable in many domains, from daily Java and Scala routines to Big Data analytics with Storm or Hadoop.
Slideshare hasn't imported my notes, so here's the link to the Google Presentation: https://goo.gl/Gl4Vhm
Haskell is a statically typed, non strict, pure functional programming language. It is often talked and blogged about, but rarely used commercially. This talk starts with a brief overview of the language, then explains how Haskell is evaluated and how it deals with non-determinism and side effects using only pure functions. The suitability of Haskell for real world data science is then discussed, along with some examples of its users, a small Haskell-powered visualization, and an overview of useful packages for data science. Finally, Accelerate is introduced, an embedded DSL for array computations on the GPU, and an ongoing attempt to use it as the basis for a deep learning package.
Temporal logic and functional reactive programmingSergei Winitzki
In my day job, most bugs come from imperatively implemented reactive programs. Temporal Logic and FRP are declarative approaches that promise to solve my problems. I will briey review the motivations behind
and the connections between temporal logic and FRP. I propose a rather "pedestrian" approach to propositional linear-time temporal logic (LTL), showing how to perform calculations in LTL and how to synthesize programs from LTL formulas. I intend to explain why LTL largely failed to
solve the synthesis problem, and how FRP tries to cope.
FRP can be formulated as a -calculus with types given by the propositional intuitionistic LTL. I will discuss the limitations of this approach, and outline the features of FRP that are required by typical application programming scenarios. My talk will be largely self-contained and should be understandable to anyone familiar with Curry-Howard and functional programming.
1. Variables - Learn to conveniently store data in your Python programs!
2. Numbers - Learn how numbers work behind the scenes in your Python programs!
3. Strings - Master the written word and automate messages using text!
4. Logic and Data Structures - Teach your Python programs to think and decide!
5. Loops - Save time and effort, by making computers do the hard work for you!
6. Functions - Automate Tasks by Creating your very own Python Functions that you can use over and over!
7. OOP - Add Python to Your Resumé By Mastering Object-Oriented Programming, an industry-standard programming technique!
There are many popular stream libraries for Scala developers, including Akka Streams, scalaz-stream, fs2, plus others in the Java ecosystem. While all excellent choices for building reactive Scala applications, their reliance on effects makes them particularly difficult to test and reason about. In this talk, long-time Scala functional programmer John A. De Goes takes to the stage to demonstrate a new approach to modeling streams that requires less machinery and has more reasoning power, composability, flexibility, and testability than many other approaches. By attending the talk, you'll learn how the best stream library may be the one you get for (co)free!
Slideshare hasn't imported my notes, so here's the link to the Google Presentation: https://goo.gl/Gl4Vhm
Haskell is a statically typed, non strict, pure functional programming language. It is often talked and blogged about, but rarely used commercially. This talk starts with a brief overview of the language, then explains how Haskell is evaluated and how it deals with non-determinism and side effects using only pure functions. The suitability of Haskell for real world data science is then discussed, along with some examples of its users, a small Haskell-powered visualization, and an overview of useful packages for data science. Finally, Accelerate is introduced, an embedded DSL for array computations on the GPU, and an ongoing attempt to use it as the basis for a deep learning package.
Temporal logic and functional reactive programmingSergei Winitzki
In my day job, most bugs come from imperatively implemented reactive programs. Temporal Logic and FRP are declarative approaches that promise to solve my problems. I will briey review the motivations behind
and the connections between temporal logic and FRP. I propose a rather "pedestrian" approach to propositional linear-time temporal logic (LTL), showing how to perform calculations in LTL and how to synthesize programs from LTL formulas. I intend to explain why LTL largely failed to
solve the synthesis problem, and how FRP tries to cope.
FRP can be formulated as a -calculus with types given by the propositional intuitionistic LTL. I will discuss the limitations of this approach, and outline the features of FRP that are required by typical application programming scenarios. My talk will be largely self-contained and should be understandable to anyone familiar with Curry-Howard and functional programming.
1. Variables - Learn to conveniently store data in your Python programs!
2. Numbers - Learn how numbers work behind the scenes in your Python programs!
3. Strings - Master the written word and automate messages using text!
4. Logic and Data Structures - Teach your Python programs to think and decide!
5. Loops - Save time and effort, by making computers do the hard work for you!
6. Functions - Automate Tasks by Creating your very own Python Functions that you can use over and over!
7. OOP - Add Python to Your Resumé By Mastering Object-Oriented Programming, an industry-standard programming technique!
There are many popular stream libraries for Scala developers, including Akka Streams, scalaz-stream, fs2, plus others in the Java ecosystem. While all excellent choices for building reactive Scala applications, their reliance on effects makes them particularly difficult to test and reason about. In this talk, long-time Scala functional programmer John A. De Goes takes to the stage to demonstrate a new approach to modeling streams that requires less machinery and has more reasoning power, composability, flexibility, and testability than many other approaches. By attending the talk, you'll learn how the best stream library may be the one you get for (co)free!
Free monads and free applicatives have proven an incredibly useful tool in repertoire of the functional programmer: they separate concerns, encourage denotational semantics for program specification, allow easy and type-safe mocking of purely functional code, and allow dynamic introspection and optimization.
Despite these benefits, free monads are notoriously constrained: by themselves, they cannot handle parallelism (only sequentiality), and because they provide only a monad, richer structures (such as monads that fail, or monads that support alternation) cannot be expressed without crude hacks that limit composability and expressiveness.
In this session, John A. De Goes shows how the free monad can be deconstructed for its individual features, and then rebuilt using a more powerful technique that enables more extensibility. The resulting structure — no longer technically a "free monad" — allows reification of as few or as many aspects of computation as are necessary to model the problem domain.
After the session, attendees will know how to augment their existing free programs to add parallelism, racing, failure, and other aspects of computation as required by their problem. In addition, through this thorough deconstruction and reconstruction of the free monad, attendees will have a very deep understanding of reified computation and why the free monad has the structure and limitations it does.
Presented on Codemotion Warsaw 2016 and JDD 2016.
Pig, Hive, Flink, Kafka, Zeppelin... if you now wonder if someone just tried to offend you or are those just Pokemon names, then this talk is just for you!
Big Data is everywhere and new tools for it are released almost at the speed of new JavaScript frameworks. During this entry level presentation we will walk though the challenges which Big Data presents, reflect how big is big and introduce currently most fancy and popular (mostly open source) tools.
We'll try to spark off interest in Big Data by showing application areas and by throwing ideas where you can later dive into.
Open source big data landscape and possible ITS applicationsSoftwareMill
What is big data, and how open-source big data projects, such as Apache Spark, Kafka and Cassandra can be used in ITS (Intelligent Transport Systems) related projects.
Projekt z punktu widzenia UX designeraSoftwareMill
User Experience (UX), tłumacząc bezpośrednio na język polski, to doświadczenie użytkownika. Obecnie, intuicyjność oprogramowania ma coraz większe znaczenie dla klienta. Dlatego też coraz więcej firm zwraca uwagę na rozwijanie technik UX w swoich projektach. Ciągle jednak świadomość zarówno klientów jak i zespołów projektowych bywa niewielka w tym temacie. Internet jest wypełniony informacjami dotyczącymi User Experience, jednak trudno jest dotrzeć do źródeł dostarczających pełnej i zadowalającej wiedzy. Prelekcja ma na celu wyjaśnienie po co został stworzony UX i wprowadzenie do tematu od strony czysto psychologicznej, co pozwoli na lepsze zrozumienie schematów działania tego procesu.
Abstract:
Are the machines learning on their own? Wait, is Skynet already here? During this session we will tackle an easy Machine Learning problem, show how can it be processed on Spark including data cleaning, normalization and a learning process. Live coding session, but only if the machines don’t rise against us.
What's the best way to model modular, composable effects in your purely functional program? In this presentation, I take a look at monad transformers and free monads, discuss their history, and compare how effectively they solve the problem.
Wynaleźlismy samoloty, byliśmy na księżycu, każdy z nas widział panoramę Marsa zrobioną *na miejscu*. Mogło by się wydawać, że co się miało stać, już się stało.
Niekoniecznie.
Jesteśmy świadkami nowej rewolucji, niekoniecznie mniejszej od Rewolucji Przemysłowej dziewiętnastego wieku.
Rola pracownika w firmie się zmienia. Standardowy model wyrobnika z młotkiem, w którego próbował nas wcisnąć system edukacji, w dzisiejszej globalnej wiosce traci rację bytu.
Jak może wyglądać nowy typ firmy, w którym pracownik jest czynnikiem twórczym, a nie "resourcem"? Jak poradzić sobie z zarządzaniem takim zespołem? Czy tradycyjna rola "leadera" ciągle ma sens?
Sam tego nie wiem :-). Może razem odpowiemy jakoś na te pytania.
3 kroki do sukcesu płaskiej i zdalnej firmy | SoftwareMillSoftwareMill
Prezentacja do prelekcji na konferencji InternetBeta 2015.
Kilka tipów jak prowadzić firmę w inny sposób na przykładzie SoftwareMill.
100%:
Zdalna praca
Płaska struktura organizacji
Transparentności finansowa
Hej! Masz pytania? Daj znać na hello@softwaremill.com
The Easy-Peasy-Lemon-Squeezy, Statically-Typed, Purely Functional Programming...John De Goes
Maybe you've played around with functional programming before, but don't consider yourself a functional programmer. Or maybe you program functionally, but only in a dynamically-typed programming language. Or MAYBE you just like workshops with really long, ridiculously-sounding titles!
No matter, this workshop that teaches the super hot programming language PureScript is guaranteed to cure what ails you!
Come, learn about functions, learn about types, learn about data, and learn about how to smash them all together to build beautiful programs that are easy to test, easy to combine, and easy to reason about.
Become the functional programmer you were born to be!
Http4s, Doobie and Circe: The Functional Web StackGaryCoady
Http4s, Doobie and Circe together form a nice platform for building web services. This presentations provides an introduction to using them to build your own service.
La programmation fonctionnelle est un style de programmation qui commence à se populariser. Cependant, elle garde un côté compliqué et inaccessible ce qui n'est absolument pas le cas.
Le but de cette présentation est de montrer pourquoi la programmation fonctionnelle est intéressante et surtout comment s'y mettre par petites étapes :)
Les exemples sont montrés en JavaScript / Java / Scala pour rester le plus accessible et voir les différences entre ces langages.
…or how to play with EcmaScript shortcoming.
This talk discuss about how I implemented a clear, elegant, succinct and safe syntax to do Pattern Matching in modern JavaScript.
Dynamic Programming is an algorithmic paradigm that solves a given complex problem by breaking it into subproblems and stores the results of subproblems to avoid computing the same results again.
An overview of the Idris functional programming language. Idris has a number of interesting features such as dependent types, function totality checking and theorem proving.
A dive into the world of Lambda expressions in JDK 8, covering the fundamental ideas, some gotchas and a discussion of performance. Finally, just how far can you take Lambdas in Java?
I really enjoy giving live coding talks. They let me demonstrate concrete usages of a tool or library that work, rather than "almost work, but...". Although the opinions vary, I'd argue that it's possible to deliver an awesome live coding talk - provided that you come well prepared. Having already given a couple of live coding sessions, I'd like to share the lessons I've learned.
If you're planning to prepare you own live coding session, the tips&tricks presented here will help you feel more comfortable and prepared for (almost) everything. Real-life horror stories included!
Goryle i ser szwajcarski. Czego medycyna ratunkowa może Cię nauczyć o tworzen...SoftwareMill
Im dłużej pracujemy w jakiejś branży, tym częściej dostrzegamy, że wiele koncepcji, z którymi się stykamy, wcale nie jest nowych i że gdzieś już je wcześniej spotkaliśmy. Co więcej, zaczynamy też dostrzegać różne analogie z innymi - na pozór bardzo odległymi - branżami czy dziedzinami wiedzy. Okazuje się, że aby dostrzec te analogie, wystarczy dobrze znać jedną z tych dziedzin a w pozostałych z grubsza się orientować.
Podczas tej prezentacji przyjrzymy się nieoczywistym analogiom pomiędzy szeroko pojętym programowaniem a medycyną ratunkową, która też ma swój ruch na kształt software craftsmanship. Wiedza medyczna nie jest wymagana.
Reactive Integration with Akka Streams and AlpakkaSoftwareMill
An alpaca is like a camel, but is Alpakka like Apache Camel? Can we use the reactive approach in the area of integration as well, instead of the blocking approach that Camel usually offers?
In this live coding session we’re going to explore the possibilities that Alpakka - a set of connectors for Akka Streams - offers to fetch data from various data sources and send it to different destinations. Using those, you’re going to learn, on a working example, how to build a reactive integration layer with the help of Akka Streams - one of the most popular Reactive Streams implementation.
A short introduction in to chatbots and how to use AI to improves their possibilities. Presents how to use IBM Watson and wit.ai to create user friendly bots.
Pig, Hive, Flink, Kafka, Zeppelin... if you now wonder if someone just tried to offend you or are those just Pokemon names, then this talk is just for you!
Big Data is everywhere and new tools for it are released almost at the speed of new JavaScript frameworks. During this entry level presentation I will walk though the challenges which Big Data presents, reflect how big is big and introduce currently most fancy and popular (mostly open source) tools.
I'll try to spark off interest in Big Data by showing application areas and by throwing ideas where you can later dive into.
Out-of-the-box Reactive Streams with Java 9SoftwareMill
Reactive Streams is a standard for asynchronous data processing in a streaming fashion with non-blocking backpressure. Starting from Java 9, they have become a part of the JDK in the form of the java.util.concurrent.Flow interfaces.
In this live coding session we’re going to go through the basic concepts of reactive stream processing and see how to use the APIs included in JDK 9.
Hiring, Bots and Beer. (Hiring in the IT industry) SoftwareMill
How does hiring look like from the IT company point of view. How to remedy the difficulties in the recruitment process. Why automation all the menial tasks can influence on perception of candidate’s experience. Tips and tricks on how to do it in the smart way. What question in the recruitment process is the most important in our company and why it should be important for you as well?
Teal Is The New Black. czyli dlaczego transparentność i holakracja przenoszą biznes na nowy poziom.
Czy jesteś gotowy podzielić się władzą?
Jak podnieść wyniki sprzedaży poprzez wzrost efektywności pracy i lojalności pracowników, zachowując przy tym serce i duszę? Czym jest holokracja, co oznacza transparentność i jak ją wprowadzić do hierarchicznej organizacji?
Historie prawdziwe firm w sytuacjach przełomowych, kiedy "turkusowe" mechanizmy sprawdziły się w firmach z 40, 1000 i 40 000 pracowników.
premiera prezentacji: InternetBeta 2017
Apache Cassandra is one of the most renowned NoSQL databases. Although it's often associated with great scalability, improper usage might result in shooting yourself in the foot. In this talk I'll present a set of ideas and guidelines - both for developers and administrators - which will help you to make your project an epic failure.
How to manage in a flat organized, remote and transparent companySoftwareMill
No managers in company - ways of decision making.
We have no hierarchy, no managers, no vacation policy and no secrets. Full transparency (including financial) is second nature to us.
We have the courage to go against the flow and show that a company with a flat organizational structure can develop, scale and achieve goals: our own, and those of our clients.
In 30 minutes I would like to show:
1. Why is it worth to spend some time and learn Gatling - a tool for integration/performance test of your web application?
2. Under what circumstances it is necessary to have Gatling in your toolbox?
3. What are Gatling cons and what kind of problems can you expect?
For sure there is no silver bullet in testing tools area, but you will definitely love Gatling DSL.
What is most important in cooperation with external software developers? Par...SoftwareMill
What questions should be asked before making the decision?
We believe that understanding approach and principles is fundamental to successful cooperation and also could shed some light on what client could expect from software house during a project. That is why we have prepared answers for some of the most frequently asked questions.
Part 1: People
From spaghetti with no `src/test` to green CI and well-sleeping developersSoftwareMill
Jacek Kunicki & Michał Matłoka
Yes, we did it! Over a year ago we met a monster – a legacy
Spring MVC application with 50% code duplication, no tests,
manual deployment and mysterious error reporting. Come and
see yourself how blood, sweat and tears have then turned
into a well-tested REST API, pleasant to use and develop.
After a year we have an interactive API documentation, informative
call statuses and error messages. We precisely track every
request through its entire lifecycle. Together with version
tracking on multiple nodes, this lets us spot any errors
really quickly.
Plus, we reduced the boilerplate needed to achieve all of this to
a single annotation for each API call – with the help of
AspectJ, MDC, custom filters, converters and more.
Obviously, we also introduced src/test/groovy, full of Spock
and rest-assured – which made our application “the most
rigid part of the infrastructure”, as per our customer.
Come to hear our story, share yours and let us know if we could do better!
In this talk I would like to present few recently discovered security vulnerabilities in the Apache Struts 2 web framework and based on that try to increase developers' awareness of the overall application security. In my opinion, nowadays developers don’t care about the security too much, they depend on what the framework gives them. Quite often, then even don’t check security bulletins to see if a new vulnerability wasn’t discovered recently in his/her famous framework. I would like show few web attacks and explain how it was possible to harm an application or even entire server, how to prevent such kind of attacks in the future and so on. Examples will base on the Apache Struts 2, but almost all the same problems were pointed out in the Spring MVC or in the Apache Wicket. Each framework has its own weaknesses :-)
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
Generating a custom Ruby SDK for your web service or Rails API using Smithyg2nightmarescribd
Have you ever wanted a Ruby client API to communicate with your web service? Smithy is a protocol-agnostic language for defining services and SDKs. Smithy Ruby is an implementation of Smithy that generates a Ruby SDK using a Smithy model. In this talk, we will explore Smithy and Smithy Ruby to learn how to generate custom feature-rich SDKs that can communicate with any web service, such as a Rails JSON API.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
Here is something new! In our next Connector Corner webinar, we will demonstrate how you can use a single workflow to:
Create a campaign using Mailchimp with merge tags/fields
Send an interactive Slack channel message (using buttons)
Have the message received by managers and peers along with a test email for review
But there’s more:
In a second workflow supporting the same use case, you’ll see:
Your campaign sent to target colleagues for approval
If the “Approve” button is clicked, a Jira/Zendesk ticket is created for the marketing design team
But—if the “Reject” button is pushed, colleagues will be alerted via Slack message
Join us to learn more about this new, human-in-the-loop capability, brought to you by Integration Service connectors.
And...
Speakers:
Akshay Agnihotri, Product Manager
Charlie Greenberg, Host
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
As AI technology is pushing into IT I was wondering myself, as an “infrastructure container kubernetes guy”, how get this fancy AI technology get managed from an infrastructure operational view? Is it possible to apply our lovely cloud native principals as well? What benefit’s both technologies could bring to each other?
Let me take this questions and provide you a short journey through existing deployment models and use cases for AI software. On practical examples, we discuss what cloud/on-premise strategy we may need for applying it to our own infrastructure to get it to work from an enterprise perspective. I want to give an overview about infrastructure requirements and technologies, what could be beneficial or limiting your AI use cases in an enterprise environment. An interactive Demo will give you some insides, what approaches I got already working for real.
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
Neuro-symbolic (NeSy) AI is on the rise. However, simply machine learning on just any symbolic structure is not sufficient to really harvest the gains of NeSy. These will only be gained when the symbolic structures have an actual semantics. I give an operational definition of semantics as “predictable inference”.
All of this illustrated with link prediction over knowledge graphs, but the argument is general.
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
When stars align: studies in data quality, knowledge graphs, and machine lear...
Origins of free
1. THE ORIGINS OF FREE
Adam Warski, SoftwareMill
10/2/2017, LambdaDays
2. @adamwarski, SoftwareMill, LambdaDays 2017
THE PLAN
➤ Why bother?
➤ Universal algebra
➤ Free algebras
➤ The meaning of life free
➤ Monads & free monads
➤ Free monads in Haskell, Cats and Scalaz
➤ It’s simpler than it sounds
3. @adamwarski, SoftwareMill, LambdaDays 2017
WHY BOTHER WITH FREE?
➤ Define a composable program
➤ Using high-level custom instructions
➤ Run it in context later, given instruction interpretation
def issueCreditCard(u: UserId): Free[BankOps, CreditLimit] = for {
user <- LookupUserData(u).liftFree
otherCredits <- FetchOtherCredits(user).liftFree
val limit = calculateLimit(user, otherCredits)
creditCard <- IssueNewCard(user, limit).liftFree
_ <- SendEmail(user.email, cardIssuedEmail(user, limit)).liftFree
} yield limit
4. @adamwarski, SoftwareMill, LambdaDays 2017
WHY BOTHER WITH FREE?
def issueCreditCard(u: UserId): Free[BankOps, CreditLimit] = for {
user <- LookupUserData(u).liftFree
otherCredits <- FetchOtherCredits(user).liftFree
val limit = calculateLimit(user, otherCredits)
creditCard <- IssueNewCard(user, limit).liftFree
_ <- SendEmail(user.email, cardIssuedEmail(user, limit)).liftFree
} yield limit
val productionInterpreter: BankOp ~> Future = {
override def apply[A](bo: BankOp[A]): Future[A] = bo match {
case LookupUserData(u) => oracleDB2dao.lookupUser(u)
case FetchOtherCredits(user) =>
legacySoapSystem.fetchCredits(user)
// …
}
}
5. @adamwarski, SoftwareMill, LambdaDays 2017
WHY BOTHER WITH FREE?
val testInterpreter: BankOp ~> Id = {
override def apply[A](bo: BankOp[A]): Id[A] = bo match {
case LookupUserData(u) => new User(…)
case FetchOtherCredits(user) => List(Credit(1000000.usd))
// …
}
}
def issueCreditCard(u: UserId): Free[BankOps, CreditLimit] = for {
user <- LookupUserData(u).liftFree
otherCredits <- FetchOtherCredits(user).liftFree
val limit = calculateLimit(user, otherCredits)
creditCard <- IssueNewCard(user, limit).liftFree
_ <- SendEmail(user.email, cardIssuedEmail(user, limit)).liftFree
} yield limit
6. @adamwarski, SoftwareMill, LambdaDays 2017
WHY BOTHER WITH FREE?
val result: CreditLimit = issueCreditCard(UserId(42))
.foldMap(testInterpreter)
def issueCreditCard(u: UserId): Free[BankOps, CreditLimit] = for {
user <- LookupUserData(u).liftFree
otherCredits <- FetchOtherCredits(user).liftFree
val limit = calculateLimit(user, otherCredits)
creditCard <- IssueNewCard(user, limit).liftFree
_ <- SendEmail(user.email, cardIssuedEmail(user, limit)).liftFree
} yield limit
7. @adamwarski, SoftwareMill, LambdaDays 2017
ABOUT ME
➤ Software Engineer, co-founder @
➤ Mainly Scala
➤ Open-source: Quicklens, MacWire, ElasticMQ, ScalaClippy, …
➤ Long time ago: student of Category Theory
8. @adamwarski, SoftwareMill, LambdaDays 2017
WHAT IS AN ALGEBRA?
“algebra is the study of mathematical symbols and the rules for manipulating these symbols"
Wikipedia, 2017
“the part of mathematics in which letters and other general symbols are used to represent numbers
and quantities in formulae and equations."
Google Search, 2017
y = ax + b
E = mc2
f(10◊x) = K(▸9)
def sum(l: List[L]) = l.fold(_ + _)
main = getCurrentTime >>= print
9. @adamwarski, SoftwareMill, LambdaDays 2017
UNIVERSAL ALGEBRA: SIGNATURE
➤ Goal: Model programs as algebras
➤ Let’s generalise!
➤ Studies algebraic structures, rather than concrete models
algebraic signature ⌃ = (S, ⌦)
set S
family ⌦ of sets indexed by S⇤
⇥ S
➤ Syntax:
➤ type names:
➤ operation names:
11. @adamwarski, SoftwareMill, LambdaDays 2017
UNIVERSAL ALGEBRA: ALGEBRA
➤ A specific interpretation of the signature
➤ for each type, a set
➤ for each operation, a function between appropriate sets
⌃ = (S, ⌦), S = {int, str} and ⌦ = {0, succ, +, ++, toString}
We can define a ⌃-algebra A:
|A|int = {0, 1, 2, ...} = N
|A|str = {”a”, ”aa”, ..., ”b”, ”ab”, ...}
succA = x.x + 1
+A = xy.x + y
. . .
12. @adamwarski, SoftwareMill, LambdaDays 2017
TERM ALGEBRA
➤ Can we build an algebra out of pure syntax?
➤ Expressions (terms) that can be built from the signature
➤ Rather boring, no interpretation at all
|T⌃|int = {0, succ(0), succ(succ(0)), ..., 0 + 0, 0 + succ(0), ...}
|T⌃|str = {toString(0), toString(succ(0)), ..., toString(0)++toString(0), ...}
succT⌃ (t) = succ(t), e.g. succT⌃ (succ(0)) = succ(succ(0))
+T⌃ (t1, t2) = t1 + t2
...
⌃ = (S, ⌦), S = {int, str} and ⌦ = {0, succ, +, ++, toString}
We define the term algebra T⌃:
13. @adamwarski, SoftwareMill, LambdaDays 2017
TERM ALGEBRA
➤ Defined inductively
➤ base: all constants are terms
➤ step: any functions we can apply on previous terms
⌃ = (S, ⌦), S = {int, str} and ⌦ = {0, succ, +, ++, toString}
{0}
{0, 0 + 0, succ(0), toString(0)}
{0, 0 + 0, succ(0), 0 + succ(0), succ(0) + 0, succ(0) + succ(0),
toString(0), toString(succ(0)), toString(0) + +toString(0)}
14. @adamwarski, SoftwareMill, LambdaDays 2017
HOMOMORPHISM
➤ Homomorphism is a function between algebras
➤ For each type, functions between type interpretations
➤ Such that operations are preserved
⌃ = (S, ⌦), S = {int, str} and ⌦ = {0, succ, +, ++, toString}
When A and B are ⌃-algebras, f : A ! B is a homomorphism when:
fint : |A|int ! |B|int
fstr : |A|str ! |B|str
8x2|A|int
fint(succA(x)) = succB(fint(x))
8xy2|A|int
f(x +A y) = f(x) +B f(y)
8x2|A|int
fstr(toStringA(x)) = toStringB(fint(x))
15. @adamwarski, SoftwareMill, LambdaDays 2017
INITIAL ALGEBRA
⌃-algebra I is initial when for any other
⌃-algebra A there is exactly one
homomorphism between them.
Theorem 1 T⌃ is initial
16. @adamwarski, SoftwareMill, LambdaDays 2017
INITIAL ALGEBRA
Theorem 1 T⌃ is initial
⌃ = (S, ⌦), S = {int, str} and ⌦ = {0, succ, +, ++, toString}
|A|int = {0, 1, 2, ...} = N
|A|str = {”a”, ”aa”, ..., ”b”, ”ab”, ...}
succA = x.x + 1
+A = xy.x + y
. . .
We can define a ⌃-algebra A:
f : T⌃ ! A
f(0T⌃ ) = 0A
f(succT⌃ (t)) = succA(f(t))
...
17. @adamwarski, SoftwareMill, LambdaDays 2017
INITIAL ALGEBRA
➤ Only one way to interpret a term
➤ no junk: term algebra contains only what’s absolutely necessary
➤ no confusion: no two values are combined if they don’t need to be
➤ There’s only one initial algebra (up to isomorphism)
⌃-algebra I is initial when for any other
⌃-algebra A there is exactly one
homomorphism between them.
Theorem 1 T⌃ is initial
18. @adamwarski, SoftwareMill, LambdaDays 2017
INITIAL ALGEBRA
➤ This algebra is definitely not initial:
⌃ = (S, ⌦), S = {int, str} and ⌦ = {0, succ, +, ++, toString}
➤ Junk: strings “a”, “b”, …
➤ Confusion: 0+succ(0) is same as succ(0)+0
We can define a ⌃-algebra A:
|A|int = {0, 1, 2, ...} = N
|A|str = {”a”, ”aa”, ..., ”b”, ”ab”, ...}
19. @adamwarski, SoftwareMill, LambdaDays 2017
FREE ALGEBRA
For any set X, T⌃(X) is the term algebra with X added as ”constants”
(but called variables)
⌃ = (S, ⌦), S = {int, str} and ⌦ = {0, succ, +, ++, toString}
Xint = {i, j, k}
Xstr = {s1, s2}
succ(i) + j + succ(succ(k))
s1 + +toString(0)
toString(succ(0) + k) + +s2
20. @adamwarski, SoftwareMill, LambdaDays 2017
FREE ALGEBRA
➤ An interpretation of the variables determines an interpretation of any term
Theorem 1 For any variable set X, T⌃(X) is free
For any set X, T⌃(X) is the term algebra with X added as ”constants”
(but called variables)
⌃-algebra I is free over X (X ⇢ I) when for any other
⌃-algebra A, any function f : X ! |A| extends uniquely
to a homomorphism f#
: I ! A between them.
22. @adamwarski, SoftwareMill, LambdaDays 2017
MEANING OF FREE
➤ Free to interpret in any way
➤ no constraints
➤ Free of additional structure
➤ only what’s absolutely necessary
➤ No junk, no confusion
23. @adamwarski, SoftwareMill, LambdaDays 2017
FREE RECAP
➤ Algebraic signature:
➤ All possible interpretations: algebras
➤ For any variable set
➤ The term algebra is free
➤ any interpretation of the variables
➤ determines an interpretation of any term
➤ A general construction
⌃ = (S, ⌦)
X
T⌃(X)
f : X ! |A|
f#
: T⌃(X) ! A
24. @adamwarski, SoftwareMill, LambdaDays 2017
MODELLING SEQUENTIAL PROGRAMS: MONADS
➤ A sequential program can:
➤ return a value (pure)
➤ compute what to do next basing on previous result (flatMap)
➤ People decided to call an object with such operations a Monad
➤ Hence, we’ll use Monads to represent programs as data
➤ + sanity laws
25. @adamwarski, SoftwareMill, LambdaDays 2017
FREE MONAD
➤ Signature ~ pure + flatMap
➤ Variables ~ operations (our DSL)
➤ Free Monad ~ terms built out of pure, flatMap, our DSL
➤ modulo monad laws!
➤ e.g. flatMap(pure(x), f) = f(x)
Interpretation of the DSL determines the interpretation of the whole program
26. @adamwarski, SoftwareMill, LambdaDays 2017
FREE MONAD
➤ Our “world” (category) are Scala/Haskell/… monads (not algebras)
➤ The “world” (category) of the variables are generic Scala/Haskell/… terms (not sets)
➤ Signature:
➤ types: M[_]
➤ operations:
➤ pure[A]: A => M[A]
➤ flatMap[A, B](ma: M[A], f: A => M[B]): M[B]
➤ Modulo monad laws
27. @adamwarski, SoftwareMill, LambdaDays 2017
FREE IN CATS/SCALAZ
trait Free[F[_], A]
object Free {
case class Pure[F[_], A](a: A) extends Free[F, A]
case class Suspend[F[_], A](a: F[A]) extends Free[F, A]
case class FlatMapped[F[_], B, C](
c: Free[F, C], f: C => Free[F, B] extends Free[F, B]
}
28. @adamwarski, SoftwareMill, LambdaDays 2017
FREE IN HASKELL
data Free f r = Free (f (Free f r)) | Pure r
trait Free[F[_], A]
object Free {
case class Pure[F[_], A](a: A) extends Free[F, A]
case class Join[F[_], A](f: F[Free[F, A]]) extends Free[S, A]
}
f/F[_] must be a functor!
29. @adamwarski, SoftwareMill, LambdaDays 2017
SUMMING UP
➤ Direct construction of free algebras
➤ Hand-wavy construction of free monad
➤ Free
➤ free to interpret in any way
➤ free of constraints
➤ no junk, no confusion
➤ Free in Haskell is the same free as in Scala
30. @adamwarski, SoftwareMill, LambdaDays 2017
FURTHER READING
➤ “Foundations of Algebraic Specification and Formal
Software Development” by Donald Sannella and
Andrzej Tarlecki
➤ The Internet