Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Opaque Argument Type with type system

Opaque Argument Type with type system

Takuma Shimizu

April 12, 2019
Tweet

More Decks by Takuma Shimizu

Other Decks in Programming

Transcript

  1. Opaque Argument Type
    Λͻ΋ͱ͘
    .PCJMF"DU04","

    View Slide

  2. w ਗ਼ਫ୓ຏ
    w!IPLVSPO
    wυϝΠϯۦಈઃܭ
    w J04
    w 3VCZPO3BJMT
    w 3VTU
    wϑΣϯϦϧגࣜձࣾ

    View Slide

  3. IUUQTRJJUBDPNLPIFSJUFNTEGEDFG

    View Slide

  4. ͷ

    View Slide

  5. Opaque Argument Type
    Λͻ΋ͱ͘

    View Slide

  6. Opaque Argument Type
    w Ҿ਺ͷ৔ॴʹҐஔ͢Δsome Protocol
    w ௨ৗͷHFOFSJDTͱಉ͡ৼΔ෣͍
    w TQFDJBMJ[BUJPO
    w ݺͼग़͠ଆ͕۩ମతͳܕΛܾఆ

    View Slide

  7. Opaque Argument Type
    // generics
    func useAnimal(_ animal: A) {
    animal.foo()
    }
    // Opaque Argument Type
    func useAnimal(_ animal: some Animal) {
    animal.foo()
    }

    View Slide

  8. Opaque Argument Type
    // generics
    func useAnimal(_ animal: A) {
    animal.foo()
    }
    // Opaque Argument Type
    func useAnimal(_ animal: some Animal) {
    animal.foo()
    }

    ಉ౳

    View Slide

  9. Opaque Argument Type
    // generics
    func useAnimal(_ animal: A) {
    animal.foo()
    }
    // Opaque Argument Type
    func useAnimal(_ animal: some Animal) {
    animal.foo()
    }

    ಉ౳ ˡͳΜͰʁ

    View Slide

  10. ྔԽ
    2VBOUJpDBUJPO

    View Slide


  11. w શশྔԽࢠීวʙ
    w VOJWFSTBMRVBOUJpFS
    w HFOFSJDT
    શশه߸
    㱼ΨϯμϜͰ͓ͳ͡
    Έͷه߸

    View Slide


  12. w ଘࡏྔԽࢠ
    w FYJTUFOUJBMRVBOUJpFS
    w 0QBRVF"SHVNFOU5ZQF
    ଘࡏه߸
    ΧλΧφͷ
    ʮϤʯͬΆ͍

    View Slide

  13. func useAnimal(_ animal: A) {
    animal.foo()
    }
    ∀ A. (func(A: Animal) -> ())

    શশྔԽܕ
    func(∃ A. A: Animal) -> ()

    ଘࡏྔԽܕ
    func useAnimal(_ animal: some Animal) {
    animal.foo()
    }

    View Slide

  14. (∀ x. (P(x) → Q))

    શশྔԽܕ
    ((∃ x. P(x)) → Q)

    ଘࡏྔԽܕ
    ∀ A. (func(A: Animal) -> ())
    func(∃ A. A: Animal) -> ()

    View Slide

  15. (∀ x. (P(x) → Q)) ((∃ x. P(x)) → Q)


    ͜ͷه߸͸ʮಉ஋ʯͷҙຯͰ͢

    View Slide

  16. • func(∃ S. S: Foo) -> T ͕͋Δͱ͖
    • ∀ S. (func(S: Foo) -> T) ΛߏஙͰ͖Δ
    • ٯ΋·ͨવΓ




    • func(∃ S. S: Foo) -> T ͕͋Δͱ͖
    • ∀ S. (func(S: Foo) -> T) ΛߏஙͰ͖Δ
    • ٯ΋·ͨવΓ
    w ௚؍ओٛ࿦ཧʹ͓͍ͯ੒Γཱͭ
    w ΧϦʔʹϋϫʔυಉܕରԠ
    w ໋୊ʹܕ GPSNVMBFBTUZQFT

    w ͜ΕʹΑ໋ͬͯ୊ͱܕͷؒʹ͸௚઀తͳରԠؔ܎͕͋Δ͜ͱ͕
    ɹ໋୊
    (∀ x. (P(x) → Q)) 㱻((∃ x. P(x)) → Q)

    View Slide

  17. (∀ x. (P(x) → Q))
    ((∃ x. P(x)) → Q)

    View Slide

  18. (∀ x. (P(x) → Q))
    ((∃ x. P(x)) → Q)

    View Slide

  19. func useAnimal(_ animal: A)
    func useAnimal(_ animal: some Animal)

    View Slide

  20. ಉҰͰ͸ͳ͘ಉܗ
    ಉܗ
    ɹɹࣅͨߏ଄Λ࣋ͭ΋ͷ

    View Slide

  21. func useAnimal(_ animal: A)
    func useAnimal(_ animal: some Animal)
    શশʹର͢ΔྔԽ
    ͕ʮଘࡏʯ

    View Slide

  22. Opaque Argument Type
    w HFOFSJDT શশྔԽ
    ͱΑ͘ࣅͨߏ଄Λ࣋ͭ
    w Ϣχόʔαϧ ීวɾશশ
    ʹ͸ͳΒͳ͍
    w ಛఆͷ࣮ࡏ ଘࡏ
    ͢ΔܕΛඞͣ࣋ͭ ଘࡏྔԽ

    ࿩͠଍Γͳ͍ʜ

    View Slide

  23. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠

    View Slide