Skip to content

Instantly share code, notes, and snippets.

@bontaq
Created February 13, 2020 20:51
Show Gist options
  • Save bontaq/69be94d4706c2cd1f4d3869baddccec0 to your computer and use it in GitHub Desktop.
Save bontaq/69be94d4706c2cd1f4d3869baddccec0 to your computer and use it in GitHub Desktop.
Trying out arrow typeclasses
// in haskell
class Repr a where
repr :: a -> String
data Sku = Sku { display :: String }
instance Repr Sku where
repr sku = (display sku)
test =
let sku = Sku { display = "shoes" }
in
repr sku
// test prints "shoes"
// in kotlin
interface Repr<in F> {
fun F.repr(b: F): String
}
@extension
interface SkuEntityRepr : Repr<SkuEntity> {
override fun SkuEntity.repr(b: SkuEntity): String {
return "{ sku id }"
}
}
// SkuEntity doesn't need any constructors btw
val test = Repr.repr(SkuEntity()) // unresolved ref repr ?
val test2 = SkuEntity().repr() // unresolved ref ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment