Skip to content

Commit

Permalink
algebras => records of functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fommil committed Jul 19, 2019
1 parent 6b4c5fb commit aadda79
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
14 changes: 8 additions & 6 deletions manuscript/backmatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -579,15 +579,17 @@ topic, but it is easy to derive a typeclass for an ADT:
~~~~~~~~


## Algebras
## Records of Functions

In Scala, typeclasses and algebras are both defined as a `trait` interface.
Typeclasses are injected by the `implicit` feature and algebras are passed as
explicit parameters. There is no language-level support in Haskell for algebras:
they are just data!

Consider the simple `Console` algebra from the introduction. We can rewrite it
into Haskell as a *record of functions*:
A> *Algebra* is the somewhat confused Scala name for this concept: in Haskell it's
A> called a *record of functions*. Because it's just a record. Of functions.

Consider `Console` from the introduction. We can rewrite it into Haskell:

{lang="text"}
~~~~~~~~
Expand Down Expand Up @@ -632,9 +634,9 @@ more boilerplate but makes the code easier to read:
~~~~~~~~

Whereas in Scala this encoding may be called *Finally Tagless*, in Haskell it is
known as MTL style. Without going into details, some Scala developers didn't
understand a research paper about the performance benefits of [Generalised ADTs
in Haskell](http://okmij.org/ftp/tagless-final/index.html#tagless-final).
known as *MTL style with records of functions*. Without going into details, some
Scala developers didn't understand a research paper about the performance
benefits of [Generalised ADTs in Haskell](http://okmij.org/ftp/tagless-final/index.html#tagless-final).

An alternative to MTL style are *Extensible Effects*, also known as [Free Monad
style](http://okmij.org/ftp/Haskell/extensible/more.pdf).
Expand Down
16 changes: 10 additions & 6 deletions manuscript/book.org
Original file line number Diff line number Diff line change
Expand Up @@ -16978,15 +16978,19 @@ data List a = Nil | a :. List a
deriving (Eq, Ord)
#+END_SRC

*** Algebras
*** Records of Functions

In Scala, typeclasses and algebras are both defined as a =trait= interface.
Typeclasses are injected by the =implicit= feature and algebras are passed as
explicit parameters. There is no language-level support in Haskell for algebras:
they are just data!

Consider the simple =Console= algebra from the introduction. We can rewrite it
into Haskell as a /record of functions/:
#+BEGIN_ASIDE
/Algebra/ is the somewhat confused Scala name for this concept: in Haskell it's
called a /record of functions/. Because it's just a record. Of functions.
#+END_ASIDE

Consider =Console= from the introduction. We can rewrite it into Haskell:

#+BEGIN_SRC haskell
data Console m = Console
Expand Down Expand Up @@ -17027,9 +17031,9 @@ echo Console{readln, println} = do line <- readln
#+END_SRC

Whereas in Scala this encoding may be called /Finally Tagless/, in Haskell it is
known as MTL style. Without going into details, some Scala developers didn't
understand a research paper about the performance benefits of [[http://okmij.org/ftp/tagless-final/index.html#tagless-final][Generalised ADTs
in Haskell]].
known as /MTL style with records of functions/. Without going into details, some
Scala developers didn't understand a research paper about the performance
benefits of [[http://okmij.org/ftp/tagless-final/index.html#tagless-final][Generalised ADTs in Haskell]].

An alternative to MTL style are /Extensible Effects/, also known as [[http://okmij.org/ftp/Haskell/extensible/more.pdf][Free Monad
style]].
Expand Down

0 comments on commit aadda79

Please sign in to comment.