Tagless final is the most efficient compared to ot...
# functional
r
Tagless final is the most efficient compared to other approaches based on ADTs and sealed hierarchies where you reify as values operations because it means fewer allocations. It's just standard method dispatch. It also allows polymorphism (You can code forgetting about actual data types like Deferred, Observable) etc and just represent those return values in terms of
Kind<F, A>
where F represents a box containing a value. With this style you add powers to the box by bringing in Type classes like
Async
etc.. in the example. The example can run untouched to
Deferred
,
Observable
, etc. in the same way is now concrete to IO at the edge. Such type classes activate syntax over the box. So basically you are defining an entire program in terms of the functions that it needs to compute but you are not getting married to a particular runtime provided by a third party. It's not that is better than function composition, it's that it allows you to write abstract code and you avoid extra lambda allocations since the type class constrains are themselves pure values so you can pass them around to activate syntax in global scopes. For example
Async
there brings in all it's syntax including Monad etc over the scope of the class it is injected into. This is all compile time and you get for free thousands of tests for the actual datatype you target at the edge. Each of the type classes contain laws and tests to verify the data type implements properly things like say the
Monad
contract.