Giter Club home page Giter Club logo

tagless-final-jam's Introduction

Tagless Final and Abstract Effects

Introduction

One of the core tenants of functional programming, is that the effects our programs use should be expressed in the type signatures of our functions.

For example

  • scala.Option is an effect that indicates a value may, or may not be present.
  • scala.util.Try is an effect that represents a computation that may fail, with an exception

As with all aspects of functional programming, we strive for composability. In Haskell a common approach to composing these effect types in monad transformers. However, in Scala this approach suffers from poor performance, and poor type inference.

One solution to this that has recently gained popularity is the Free Monad, which is an effect absent of interpretation. i.e. it has no inherent effect, but its effect can be defined in an arbitrary way by evaluating it using an interpreter. The free monad also has some draw backs. Performance can be an issue and there is a lot of boiler plate.

An alternative is to use Tagless Final which can be used in most of the same scenarios as the Free Monad, but achieves better performance, less boiler plate and is more simple.

The Workshop

The workshop is made up of practical exercises that introduce the tagless final style, and demonstrate how this style can be used in real world use cases.

Part 1

The first is a practical introduction to the concept of Tagless Final Interpreters with a simple first order language that can express integer arithmetic. Attendees will implement a simple evaluator for this language in the tagless final style, and show that the final and initial encodings are equivalent.

Part 2

The second part consists of several exercises that build out a simple reading list application using the tagless final style.

The exercises will demonstrate;

  • The use of higher-order tagless final encoding
  • Composing tagless final algebras
  • Using typeclass constraints to abstract over what capabilities are needed in different scenarios. Including, sequential computations with cats.Monad, error handling with cats.MonadError and parallelism with cats.Parallel

Setup

Building

  • Java 8 & SBT must be installed.
  • Clone this repository git clone https://github.com/eli-jordan/tagless-final-jam-2018
  • Run sbt update in the root of the project to download and cache all the dependencies.
  • Import the project into your favorite editor, see below for options.

Editors

There are several editors for scala

Exercises

  • Part1 – Interpreting integer arithmetic
  • Part2a – Defining the domain model for the reading list application
  • Part2b – Composing algebras with the tagless final encoding
  • Part2c – Adding error handling
  • Part2d – Adding parallelism
  • Part2e – Adding a real repository implementation, using the file system.

Answers

There are solutions to each exercise in the the /answers subdirectory.

References

tagless-final-jam's People

Contributors

eli-jordan avatar

Watchers

James Cloos avatar Ivan Oreskovic avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.