Imran/Malic
12/20/2019, 6:13 PMclass ForOp private constructor() {
companion object
}
typealias OpOf<A, X> = arrow.Kind2<ForOp, A, X>
typealias OpPartialOf<A> = arrow.Kind<ForEither, A>
@Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE")
inline fun <A, X> OpOf<A, X>.fix(): Op<A, X> =
this as Op<A, X>
@higherkind
data class Op<A, X>(val f: (X) -> A) {
fun <B> compose(other: Op<B, A>): Op<B, X> =
Op(other.f compose f)
fun <B> compose(g: (A) -> B): Op<B, X> =
compose(Op(g))
}
inline fun <A, X> Op<A, X>.k(): Kind2<ForOp, A, X> = TODO() // does that make sense?
now I want to define:
interface OpContravariant<C> : Contravariant<Conested<ForOp, C>>
How does that look like. I tried it, but I could not find something tangible.
cc @AriostonjJannis
12/20/2019, 6:18 PMOp<A, X>
looks like a wrapper like Function1<A, X>
it should have a similar contravariant instance. The instance is here: https://github.com/arrow-kt/arrow/blob/52bc681a41d44a3f14a726a125dff1c5c7e29a46/modules/core/arrow-core/src/main/kotlin/arrow/core/extensions/function1.kt#L56
And contramap is just composeinterface OpContravariant<I> : Contravariant<OpPartialOf<I>> {
override fun <A, B> Kind<OpPartialOf<I>, A>.contramap(f: (B) -> A): Kind<OpPartialOf<I>, B> =
Op(fix().f compose f)
}
Isn't this equal to the haskell version? Not sure how exactly that looked but I think this was itImran/Malic
12/20/2019, 6:41 PMJannis
12/20/2019, 6:41 PMContravariant<Conested<ForOp>, X>
is hard, is that Op<A, X>
is a wrapper for (X) -> A
and functions are contravariant in their input and covariant in their output. Contravariant<Conested<ForOp>, X>
is trying to implement contravariance in the outputImran/Malic
12/20/2019, 6:42 PMJannis
12/20/2019, 6:44 PMis there a way to upcast to Hkt. I forgot how to do thatThat is never necessary in arrow because we inherit from
Kind<F, A>
with our datatypes so inheritance takes care of that. fix()
exists because we also need to cast the other directiondata class Op<A, X>(val f: (X) -> A): OpOf<A, X>
Imran/Malic
12/20/2019, 6:46 PM