Created
February 13, 2020 20:51
-
-
Save bontaq/69be94d4706c2cd1f4d3869baddccec0 to your computer and use it in GitHub Desktop.
Trying out arrow typeclasses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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