Skip to content

Latest commit

 

History

History
31 lines (25 loc) · 2.99 KB

README.md

File metadata and controls

31 lines (25 loc) · 2.99 KB

This repository contains little (and not so little) snippets of code that illustrate techniques from functional programming, mainly.

Current gists

Some of these gists make reference or build upon results of previous ones. You'll also find some explanations throughout the code, although, surely, not enough to make them self-contained. This is the list of current gists:

  • ADTs. How do we represent embedded DSLs using algebraic data types, and how do we implement both compositional and non-compositional interpreters.
  • GADTs. How do we represent embedded DSLs using generalized algebraic data types, and how do we implement both compositional and non-compositional interpreters.
  • Church encodings. What are Church encodings and how can we pattern match against them.
  • Church encodings HK. What are Higher-Kinded Church encodings and how can we pattern match against them.
  • Church vs. ADTs. What is the relationship between these encodings? Algebras to the rescue!
  • Church vs. GADTs. Some isomorphisms between GADTs and Higher-Kinded Church encodings.
  • Natural Numbers. Shows how we can represent Natural Numbers with different encodings: Church, Scott and Parigot.
  • Bypassing Free. Check out how we can exploit object algebras to obtain the very same benefits of free monads, in many circumstances.
  • Coalgebras. What are coalgebras? How are they related to monads and algebras in general? These gists attempt to shed some light to these questions.
  • Lens, State Is Your Father. Encodings associated to a blog post. There, we provide IOCoalgebra representations for several optics, along with some interesting insights.
  • From "Hello, world!" to "Hello, monad!". Code associated to the blog post series about purification of effectful programs.
  • Macro monad. A macro that allows you to write monadic code using neither flatMaps nor for-comprehensions, but conventional syntax, i.e. semicolons. Written with a pure didactic purpose: showing that monadic code is, in essence, simple imperative code.

Executing gists

Each gist is implemented as a Scalatest file. In order to check its assertions, just enter sbt and launch the test. For instance, in order to launch the ADTs gist, enter sbt and type the following:

> test-only org.hablapps.gist.ADTs