Skip to content
/ gist Public

Little snippets of code illustrating functional programming techniques in Scala

License

Notifications You must be signed in to change notification settings

hablapps/gist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Little snippets of code illustrating functional programming techniques in Scala

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages