`Monad#fx.monad` is deprecated - apparently `fx` ...
# arrow
m
Monad#fx.monad
is deprecated - apparently
fx
will be directly on the concrete datatypes? What does this mean for custom monadic datatypes - do I need to do anything to let me write
fx
blocks with my custom monad?
s

https://youtu.be/0_zatebXMDU

m
Thanks. Is there a transcript at all? I have trouble with videos.
s
Not sure... Cc @raulraja
r
No transcript @Mickey Donaghy , we will work soon on some docs for that but we can help you here. Do you have some small sample code of what you would like it to look like or accomplish?
m
So I currently have a
DatabaseAction
monad and I'm using it like:
Copy code
val action = DatabaseAction.DatabaseActionMonad.fx.monad {
  val entity = LoadAction(Foo::class, id).bind()
  entity.foo = bah
  SaveAction(entity).bind()
  val otherEntity = LoadAction(..).bind()
  ...
}
but that
.fx
is marked as deprecated. So just want to be able to code in a similar style.
r
What does the DatabaseAction ADT look like simplified or what’s supposed to happen when you call bind() in those actions?
is this based in any way on Free or the arrow incubator MTL libs?
I can provide some sample code once I understand what bind does there
m
at the moment it's actually wrapping
Reader<MyConnection, ?>
but I want it to be opaque so that users can't just get the
MyConnection
out. Previously I've done the same thing with a free monad and I might want to do it that way too.
but in general I might want to do this for any monad I implement, shouldn't it be generic?
r
Monads can’t be generic in Kotlin without the kind emulation which forces users to call fix(). This may work after 1.5 if compiler plugins get IDE support then we can introduce kinds and effect polymorphism but until then it has to be that instead of having a monad instance you have an effect instance for your type. It’s actually less boilerplate but composition is not abstract. give me a few mins and I’ll send an example with your code
m
thanks, I've actually got to go now so no rush.
👍 1
c
@raulraja tried to run this code, got some weird compilation error with kotlin
1.4.30
Copy code
org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't inline method call 'suspended' into
public suspend fun <A> rxkoltin.Connection.db(f: suspend rxkoltin.DB<A>.() -> A, continuation: kotlin.coroutines.Continuation<rxkoltin.DBAction<A>>): kotlin.Any? defined in rxkoltin in file DbEffect.kt
r
Hi @Carlos Fernandes looks like compiler codegen bug potentially unrelated to arrow. Would you mind creating an issue in the Kotlin issue tracker? We can probably tweak the code around to make it compile but it still a compiler bug.
c
this fixed the problem:
Copy code
suspend fun <A> Connection.db(f: suspend DB<*>.() -> A): DBAction<A> {
   return Effect.Companion.suspended({
        DB(it, this)
    }, DBAction.Companion::pure, f)
}
@raulraja what's the plan now with
Union Types
? I'm wondering if those plans changed since
Higher-Kind
types is now gone
r
Union types are already encoded in Arrow Meta but for the syntax to work in the IDE so that you can call
Copy code
val x : Union2<Int, String> = 1
we need proper support for compiler plugins in the Kotlin IDEA plugin, otherwise you have to write
Copy code
val x = Union2<Int, String> = 1.first()
both compile but without IDE support the first one will be red lined as a type mismatch between int and Union2
We can potentially include them earlier but we don’t want to promote the second style which is similar to the kinds problems.
Union types and kinds are otherwise unrelated besides both in Meta being powered by proofs that are top level functions that define how implicit injections work based on types.
c
by "earlier" you men before they fix the plugin? is it plan to support Union types with arrow 1.0 ?
r
@Carlos Fernandes By earlier I mean introducing at any point the second style where you have to explicitly call first, second etc. That can be introduced in any version since it’s a new API not breaking anything else.
c
great, thanks for the clarification 🙂