Discussion: effect stack-aware composition methods #4203
anatoliykmetyuk
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Transformer Effect Types composition methods family
flatMap
,map
,semiflatMap
,subflatMap
,right
etc etc. Their names are clearly a cartesian product. ForEitherT
:(left, bi, <empty>) x ((semi, sub) x flat), traverse, <empty>) x (map, empty)
. However, this fact is not abstracted in any way. The lack of abstraction leaves "holes" in the namespace (as per Cats 1.5.0):leftSubflatMap
, though there isleftSemiflatMap
.biSubflatMap
, though there isbiSemiflatMap
.leftTraverse
, though there isbiTraverse
.Effect Type Stack Abstraction
Consider a stack of effect types:
FT[GT[HT[...[S, ?], ?], ?], A]
(later –FT :: GT :: HT :: ... :: S
for convenience; andXT[A]
meansXT[..., A]
, where...
is the "tail" – the effects followingXT
in the stack). AssumeXT
are of the kind(* -> *) -> * -> *
,X
– of the kind,* -> *
,A
,B
,C
are*
and...
indicates stack going deeply in a similar fashion.What if we want to do e.g.
A => HT[B]
orA => GT[B]
orA => S[B]
orH[A] => GT[B]
? Currently, we can't do so because the transformer effect types are not aware of the other possible nested effect types. We do not have an abstraction for a stack of effect types.Currently, we only have type classes for
F[_]
types, and not the transformer effect types (* -> *
vs(* -> *) -> * -> *
). All of thesemi-
andsub-
methods come from the transformer effect types themselves (EitherT
,OptionT
). It would be nice to have these methods separated in their own type class.However, if such a type class is to be defined, it will need the type-level information about the entire stack of effects involved. E.g.
FT :: GT :: HT :: S
is aMonad
: it has aflatMap
that works on a functionA => (FT :: GT :: HT :: S)[B]
. However, the monad type class treatsFT :: GT :: HT :: S
as* -> *
kind, it is not aware of the structure of the effect type stack. This information along won't givesemiflatMap
etc.Ideally, the end user should just provide the type classes for
X
-kind types and get theXT :: ...
-kind methods out of the box (e.g.EitherT :: IO
requiresMonad[Either]
,Monad[IO]
etc to providesemiflatMap
etc).Questions
Beta Was this translation helpful? Give feedback.
All reactions