What do you mean by `Free.monad()` Today, i tried ...
# arrow
p
What do you mean by
Free.monad()
Today, i tried to translate de Scala Cats sample into Kotlin (see https://gist.github.com/PBastiani/3598c838cbfdd982238360244b7550ed) Something seems wrong in the interpreter : i understand that in my FREE program
FreeKVStore<Unit>
is in conflict with
Kind<F, A>
! But, I don't know how to fix that...
r
should A be covariant?
p
Could you be more precise ? The Scala version of the interpreter is more intuitive to me. And, the use of the Kind type is for me +/- nebulous ....
r
What is the error you are getting when compiling?. I ment make 'A' be 'out A'. Sorry on my phone
p
Why A should be covariant ? I fixed the compilation warning. But the execution of something like that
Copy code
`val res  = KVStoreA.binding() {
       put("A", 10).bind()  //-> `java.lang.ClassCastException`
       // delete("A").bind()   //->  `kotlin.TypeCastException`
       // get("A").bind()  // -> is OK. i.e. returns None
       //   return@binding
}.fix().foldMap(impureInterpreter(), Option.monad())
gives me an exception ! The conflict coming from
FreeKVStore<Unit>
I think that
FunctionK<KVStoreA.F, F>
is not the right way to declare the natural transformation ! We do not specify any context to interpret the AST
r
Looks like the unit returning expressions in your interpreter are not lifted to Option and you are casting to it nonetheless
F in the interpreter should be concrete to ForOption and when you return an operation it should be lifted to Option
Otherwise you can make the interested depend on a Monad you use to lift to via just and pass the option Monad manually
So the cast exception is coming from the interpreter right?
p
Thx Raul for your help... I updated my interpreter with
ForId
. You mean something like that ? https://gist.github.com/PBastiani/3598c838cbfdd982238360244b7550ed Remains a warning due to the use of
Any?
I think I can improve the type checking by writing
fun <F> impureInterpreter() : FunctionK<KVStoreA.F, ForId> = object : FunctionK<KVStoreA.F,Id<A>>
i'm in the right way ?
r
On my phone but I don't think you need the type prameter F if your interpreter is fixed to ForId
Those examples should help
The problem with casting is an inference issue in the Kotlin compiler
Despite proving you cover all cases of the GADT it's unable to prove that at typechecking and you need to cast it at the end of the when expression
I plan on submitting a fix to the Kotlin compiler for GADT inference enhancements once I'm done with the arrow compiler plugins, which should remove the need to cast
FuntionK is after all a natural transformation that proves you can go from Al states of F to G and that casts should have not been necessary in the first place if the compiler infers properly the RHS
p
Thank you for your patience. I updated the Gist... Excellent news for your proposal. Type checking is a brain teaser. In fact here, it seems to me that I can put any type in Id without neither compilation warning nor execution error 🤔
Next step for this KATA : code generation with @higherkind annotation; and, the use of the State monad... for sure, with other headaches due to type checking