Tagless final name - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Georgi Lyubenov // googleson78

What's the reason "tagless final" is called that? Is it because the actions don't have "tags" (i.e. supposedly no runtime repr.), and instead are just instantiated at one point in the end before being run ("final", via transformers)?

Georgi Lyubenov // googleson78

(which seems to not currently be true for mtl)

TheMatten

As far as "final" goes, I remember something about it being slightly arbitrary name for "function-based representation / Church-like encoding" in comparison to "initial" encoding which uses normal data constructors

Georgi Lyubenov // googleson78

how is mtl related to Church encoding?

Georgi Lyubenov // googleson78

(also, I know the term is more popular in scala, maybe it means something different there? :thinking: )

TheMatten

MonadSomething m => m a is in a sense final encoding of program represented as function taking MonadSomething dictionary and calling it's methods as constructors of actions inside of the program
Compare it to Free Something a, where Something is some Functor with the actions as normal constructors

TheMatten

Hmm, or maybe Scott encoding would be a better fit

Torsten Schmits

even features a quote by @Ben Kolera !

Torsten Schmits

We can do a similar trick to the Church encoding of lists and represent our data constructors as functions. This is not a Church encoding; it's called a final encoding for reasons unknown to me. The version using explicit constructors is called an initial encoding.

so it's like Church, but different

Steven Shaw

It's best to read the original sources to find answers like this: "Finally Tagless, Partially Evaluated".

http://okmij.org/ftp/tagless-final/#tagless-final

I found an answer by one of the authors of the original paper:

The 'final' in 'finally tagless, partially evaluated' (the original paper that you skipped over) is an adjective qualifying 'tagless', and is a pun on partial evaluation's tagging-untagging problem. It does allude to final semantics (since 'final tagless' is really specifying an algebra via its polymorphic fold in a way that prevents 'peeking', unlike all initial algebra based methods) because all you can do is to call the fold. But it's still not 'final' in any reasonable way, even though there's dualities galore lurking around the corner.

https://cstheory.stackexchange.com/questions/45565/what-category-are-tagless-final-algebras-final-in#comment101261_45565

The Haskell and Scala community have been very enamored recently with what they call tagless final 'pattern' of programming. These are referenced as dual to initial free algebras, so I was wonderin...
Torsten Schmits

what other "initial algebra methods" are there?

Georgi Lyubenov // googleson78

I think that's "the definition" of an initial algebra thingy

Torsten Schmits

but Steven's quote says "all initial algebra based methods"

Georgi Lyubenov // googleson78

like, when you're defining a datatype formally (which is what adts in hs are), you're defining it as something generated as a fixpoint (so Free)

Torsten Schmits

ADTs in hs are formally defined datatypes?

Georgi Lyubenov // googleson78

I meant to say that if you want to formalise what an "adt" (in the hs sense) means in mathematics, you would (traditionally) do so via fixpoints

Georgi Lyubenov // googleson78

(as you also do with recursive functions)

Asad Saeeduddin

@Georgi Lyubenov // googleson78 did you maybe mean Fix here?