Skip to content

Instantly share code, notes, and snippets.

@niwatako
Created June 21, 2018 12:33
Show Gist options
  • Save niwatako/4c9d0f2cf482b58b206146d009ddd0f4 to your computer and use it in GitHub Desktop.
Save niwatako/4c9d0f2cf482b58b206146d009ddd0f4 to your computer and use it in GitHub Desktop.
Swiftで高カインド多相 #CodePiece #potatotips
potatotips #52 (iOS/Android開発Tips共有会) - connpass
https://potatotips.connpass.com/event/88164/
## inamiy いなみ Swiftで高カインド多相 iOS
モナドが作れる話
型コンストラクタを考える。型を引数にとり、型を返す。
たとえば `Optional<X>` は、たとえばIntいれたらOptionalIntになる。
高カインドはカインドを引数に取る
`Functor<Optional>` のような。ここで `Optional<Int>` をいれなくてよい
Swiftは目下対応予定がない。
Kotlinではできる。ARROWというファンクショナルライブラリ。Functor, Applicative, Monadなどが用意されている。
内部でKindedjを使っている。
Swiftでも負けずにやりたい。
どのアプローチお Lightweight higher
型コンストラクタを型パラメータに適用するための工夫として代用の型(タグ)を用意する。
`MyClass<Array>` と書けない代わりに、 `enum ForArray{}` を要しいて、`MyClass<ForArray>`と書く
(ここはあとで資料を見てくれ!)
`Array<T>` から `List<T>` を形式ができる
inamiy/HigherKindSwift: An experimental Higher Kinded Types in Swift.
https://github.com/inamiy/HigherKindSwift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment