Practical eff monad for micro-services

This talk presents how we use the Eff monad at Zalando to structure a REST microservice. Even when programming with functions, modules and components still matter, and I will present a new approach for dependency injection using the Reader monad (classic) and tree rewriting (what?). Then we will see how to specify more precisely several components (authentication, request to other services and database access) with the Eff monad and support additional concerns like logging or asynchronous execution.

Once you get the basic idea, the possibilities are endless! Rate limiting is just another component and another set of effects involving time and state, testing becomes really clean and easy.

 
3 favorite thumb_down thumb_up 0 comments visibility_off  Remove from Watchlist visibility  Add to Watchlist
 

Outline/structure of the Session

This talk is in 3 parts:

1. components

  • a new take on DI: start with constructor injection and add the missing pieces for easy testing and wiring with implicit readers, (optional) annotations and tree rewriting
  • how we use this approach as a library to create our components at Zalando

2. effects

  • what is the Eff monad
  • how we use it to specify the interface of components
  • some examples of effects: flowId, errors, logging, concurrent execution

3. lessons learned

  • mistakes we made
  • time: effect or component, how to decide? 

Learning Outcome

  • A new lightweight technique for dependency injection in Scala
  • Real-world examples of using the Eff monad
  • What to watch out when using the Eff monad

Target Audience

Scala developers

schedule Submitted 5 months ago

Comments Subscribe to Comments

comment Comment on this Proposal

  • 45 mins
    Demonstration
    Beginner

    In Indian classical music, we have Jugalbandi, where two lead musicians or vocalist engage in a playful competition. There is jugalbandi between Flutist and a Percussionist (say using Tabla as the instrument). Compositions rendered by flutist will be heard by the percussionist and will replay the same notes, but now on Tabla and vice-versa is also possible.

    In a similar way, we will perform Code Jugalbandi to see how the solution looks using different programming languages and paradigms.  This time the focus of code jugalbandi will be on solutioning in two different paradigms - functional programming and array-oriented paradigm.   

    During the session, Morten and Dhaval will take turns at coding the same problem using different languages and paradigms. There would be multiple such rounds during the Jugalbandi.

  • Liked Ryan Lemmer
    keyboard_arrow_down

    Haskell Design Patterns

    480 mins
    Workshop
    Intermediate

    In this workshop we explore several areas of advances that make up Modern Haskell.

    (This is an experiential workshop, we will code together, and explore ideas together from first principles. You will need GHC 7.10 and up.)

    Patterns for IO

    Experience the 3 styles of IO programming in Haskell, in the order in which they evolved:

    * imperative style (the status quo)
    * Lazy IO and its limitations
    * Iteratee IO, the solution to Lazy IO

    As we compare the different styles, we will pay attention to

    * what controls evaluation
    * space and resource management
    * the relationship between producer and consumer

    From Foldable, Traversable to Lenses

    We follow the evolution of fold and map on lists, to their generalisation over arbitrary types with the Foldable and Traversable type-classes. 

    The Lens library raises Foldable and Traversable to an even higher level of abstraction. We will see how the Lens library gives a unified vocabulary for traversal of arbitrary data structures.

    Functor, Applicative, Arrow, Monad

    These data types fall on a spectrum of power and generality (Functor being the most general, and Monad the most powerful). By experiencing how these types differ in the way they compose, we can gain a clearer understanding of where and how each type may be used.

    Datatype Generic Programming (bonus material)

    This style of Haskell programming is based on a simple technique: instead of defining functions for ad-hoc types, we deconstruct our types into a more fundamental type representation, and then write generic functions against the lower-level type. These generic functions are impervious to changes in the original, higher-level data types.

    We will experience datatype generic programming from first principles, and along the way uncover the key ingredient in the magic sauce called GHC.Generics.

  • Liked Eric Torreborre
    keyboard_arrow_down

    The Eff monad, one monad to rule them all!

    Eric Torreborre
    Eric Torreborre
    Senior Software Developer
    Zalando
    schedule 5 months ago
    Sold Out!
    45 mins
    Talk
    Advanced

    Monad transformers are a neat way to compose effectful computations: pass some configuration, read/write from disk, track errors... However they can be a bit cumbersome to deal with, especially if you want to use different stacks sharing some common effects: for example a stack to interact with AWS and another one for Hadoop computations.

    This talk will shortly introduce monad transformers in Scala and their drawbacks then present the Eff monad.

    The Eff monad has some really interesting properties:

    • effects can be developed completely independently from each other
    • effects can be interpreted in different ways and the interpreters can be composed together
    • it is based on an efficient "Free monad" (avoiding the issue of quadratic flatMaps)
    • with the Eff monad you will never have to re-implement the Monad operations (point / flatMap) again!
  • Liked Shri Vignesh Balasubramaniam
    keyboard_arrow_down

    Understanding some basic FP constructs by writing a simple Programming Language

    45 mins
    Demonstration
    Beginner

    What I cannot create, I do not understand - Richard Feynman

    Most of the time, we end up being consumers of a language. Language creation is not something which many of us do as part of our daily job. And as such, we become consumers of using various concepts like types of a language, functions-as-first-class citizens, closures, let expressions, etc. But what are these? What is semantics behind them? And how do language creators enable a language to have these? Once we understand what these mean, we go beyond the language specific implementations and can be true polyglots who can think in terms of these composable abstractions.

    This beginner focussed talk+demonstration hopes to clarify few fundamental concepts by building a language from the ground up. This talk has its foundations in a couple of academic courses which I got to be part of during 2012/2013.

    Using Racket(a variant of Scheme) as a vehicle, a hypothesized programming language (MathL) is introduced with its specifications, syntax, and rules. And slowly this language is built up with more features.The language is realized via an interpreter/executor. [We would not be discussing compilers here].
    Some tests also would be done which would help to verify the language implementation.

     

     

     

  • Liked Abhiroop Sarkar
    keyboard_arrow_down

    Wormholes and teleporting with Transient.

    45 mins
    Talk
    Intermediate

    The transient library in Haskell/Eta composes arbitrary pieces of software in concurrent, parallel and sequential settings using standard Haskell/Eta combinators like applicative, alternative, bind etc. It provides algebraic and monadically composable primitives for concurrency, parallelism, event handling, transactions and multithreading

    It liberates the programmers from dealing with state machines, objects frameworks, routes, configurations and callbacks. Transient expresses business functionalities as compact category theoretical expressions which compose. These compositions are verified during compilation, although the code might be executing in different machines.

    It presents a fresh new approach to programming concurrent and distributed systems.

     

  • Liked Eric Torreborre
    keyboard_arrow_down

    Streams, effects and beautiful folds, a winning trilogy

    Eric Torreborre
    Eric Torreborre
    Senior Software Developer
    Zalando
    schedule 5 months ago
    Sold Out!
    45 mins
    Talk
    Intermediate

    Most applications are just reading data, transforming it and writing it somewhere else. And there are great libraries in the Scala eco-system to support these use cases: Akka-Stream, fs2, Monix,... But if you look under the hood and try to understand how those libraries work you might be a bit scared by their complexity!

    In this talk you will learn how to build a very minimal "streaming library" where all the difficult concerns are left to other libraries: eff for asynchronous computations and resources management, origami for extracting useful data out of the stream. Then you will decide how to spend your complexity budget and when you should pay for more powerful abstractions.

  • Liked Kartihkeyan
    keyboard_arrow_down

    Go (pure) functional on jvm with Frege

    Kartihkeyan
    Kartihkeyan
    MTS
    Owler
    schedule 1 month ago
    Sold Out!
    20 mins
    Talk
    Beginner

     Frege is the Haskell for JVM. Like Haskell, it is purely functional, enjoys a strong static type system with global type inference and is also non-strict. JVM doesn't support any such pure functional language to feed your functional thirst. Time to have fun with Frege.