Scala

featured image

Interpreter Basics

Interpreter is a language (or program) to evaluate expressions and execute code. The intent is to keep the evaluation lazy and pure. There are 3 different kinds of methods in the interpreter pattern / Algebra.

scala fp

Monad Laws

Monad typeclass

trait Monad[F[_]]:
	def pure[A](a: A): F[A]
	def flatMap[A, B](fa: F[A])(f: A  F[B]): F[B]

Monad Laws

pure(a).flatMap(f)				= f(a)
m.flatMap(pure)						= m
m.flatMap(g).flatMap(h)		= m.flatMap(b => g(b).flatMap(h))

scala fp