Skip to content

Instantly share code, notes, and snippets.

@bontaq
Created February 13, 2020 20:51
Show Gist options
  • Select an option

  • Save bontaq/69be94d4706c2cd1f4d3869baddccec0 to your computer and use it in GitHub Desktop.

Select an option

Save bontaq/69be94d4706c2cd1f4d3869baddccec0 to your computer and use it in GitHub Desktop.

Revisions

  1. bontaq created this gist Feb 13, 2020.
    31 changes: 31 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    // 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 ?