Skip to content

Instantly share code, notes, and snippets.

Revisiting Tagless Final Interpreters

Tageless Final interpreters are an alternative to the traditional Algebraic Data Type (and generalized ADT) based implementation of the interpreter pattern. This document presents the Tageless Final approach with Scala, and shows how Dotty with it's recently added implicits functions makes the approach even more appealing. All examples are direct translations of their Haskell version presented in the Typed Tagless Final Interpreters: Lecture Notes (section 2).

The interpreter pattern has recently received a lot of attention in the Scala community. A lot of efforts have been invested in trying to address the biggest shortcomings of ADT/GADT based solutions: extensibility. One can first look at cats' Inject typeclass for an implementation of [Data Type à la Carte](http://www.cs.ru.nl/~W.Swierstra/Publications/DataTypesA

@MgaMPKAy
MgaMPKAy / SimpleStateMonad.hs
Last active November 2, 2019 18:59
Trampolined state monad in Haskell, translated from RO Bjarnason's Stackless Scala With Free Monads,
newtype State s a = State {runS :: s -> (a, s)}
instance Monad (State s) where
return x = State $ \s -> (x, s)
ma >>= f = State $ \s -> let (a, s1) = runS ma s
in runS (f a) s1
get = State $ \s -> (s, s)
put x = State $ \_ -> ((), x)
@sunilnandihalli
sunilnandihalli / curry.clj
Created December 17, 2010 20:33
a macro to create fixed-arity curryable function in clojure
(defmacro def-curry-fn [name args & body]
{:pre [(not-any? #{'&} args)]}
(if (empty? args)
`(defn ~name ~args ~@body)
(let [rec-funcs (reduce (fn [l v]
`(letfn [(helper#
([] helper#)
([x#] (let [~v x#] ~l))
([x# & rest#] (let [~v x#]
(apply (helper# x#) rest#))))]