型クラスと抽象
出典: https://wiki.haskell.org/wikiupload/8/85/TMR-Issue13.pdf
宣言
class Show a where
show :: a -> String
Show
は型クラス、show
はメソッドと呼ぶ。
実装
instance Show Bool where
show True = "True"
show False = "False"
これでBool
型はShowのインスタンスになる。
例えばprint :: Show a => a -> IO ()
の型a
にはShowのインスタンスであれば何でも使うことが出来る。
- Haskellの型クラスについて | mrsekutの備忘録
- 邦訳: How to make ad-hoc polymorphism less ad hoc
- 型クラスはインターフェースとどう違うのか | プログラミング | POSTD
- Haskell/Classes and types
- The Typeclassopediaを訳しました
- When to use a type class, when to use a type
- Type classes: an exploration of the design space
- Type Classes with Functional Dependencies
- Edward Kmett - Type Classes vs. the World
- Adventure with Types in Haskell - Simon Peyton Jones
- Writing invertible functions
- Recursion Schemes
- SelectricSimian/EventualMonad
- Categories of Structures in Haskell
- Type Classes in Haskell
- How to make ad-hoc polymorphism less adhoc
- Functors, Applicatives, And Monads In Pictures
- Denotational design with type class morphisms
- Orphan instances
- C9 Lectures: Dr. Ralf Lämmel - Advanced Functional Programming - Type Classes
- Maintainable Type Classes for Haskell
- 10章:型とクラスの定義
- Scrap your type classes
- Counterexamples of Type Classes
- Interactively discovering the best type classes for Haskell functions
- Some interesting features of Haskell’s type system
- Natural numbers with addition form a monoid
- Edward Kmett - Undecidable Superclasses
- Haskell’s Type Classes: We Can Do Better
- Haskellで関数のオーバーロード
- Why I prefer typeclass-based libraries
- Typeclasses and Run-Time Dependency Management
- phadej/poly-nfdata.hs
- Type Classes and Constraints
- 入門的ではない型クラスの話:Haskellの型クラスがぁ (´^`;)
- オーバーロードは何故にかくも難しいのか:Haskellの成功と失敗
- Haskellの型クラスに関わるワークアラウンド
- Type defaulting in Haskell
- How do type classes differ from interfaces?
- 型クラスのインスタンスが複数ある場合の話(Haskell編) - きくらげ観察日記
- functor.tokyo – When is UndecidableInstances safe?
- The curse of λ - Overlapping Instancesと戦う
- On Type Class Instance Selection – Hacker Noon
- Type Class Patterns and Anti-patterns – Hacker Noon
- The Has Type Class Pattern – Hacker Noon
- 型クラスの原点 How to make ad-hoc polymorphism less ad hoc を読んだ話 - Qiita
- Scrap all your type classes but one
- 型クラスの原点 How to make ad-hoc polymorphism less ad hoc を読んだ話 - Qiita
- Counterexamples of Type Classes
- [Haskell] instance宣言に関するエラーの原因いろいろ - Qiita
- Bloggy Badger: N-ary Functors
- まともな型クラス への入門: 関数型とオブジェクト指向の垣根を越えて
- mpickering - Replacing type classes with records affects optimisation
- Algorithmically Scrapping Your Typeclasses :: Reasonably Polymorphic
- Haskellの関数に等価性を定義したい! - Qiita
- Improving Typeclass Relations by Being Open
- Fluent Polymorphism with Visible Type Applications
- Haskellで型クラス制約の和を表現する - Qiita
- Proxy arguments in class methods: a comparative analysis - Ryan Scott - 型の情報しか使わない型クラスのメソッドをどうデザインするのが良いのか
- Haskellの型クラスについて - Qiita
- simplifying-typeclasses
- Which typeclass are you? [impurepics quiz]
- Inspecting Haskell Instance Resolution
- Nicer Data Types a la Carte with DefaultSignatures
- Demystifying Type Classes
- Haskellの型クラスでJavaScriptっぽいことをやって遊んでみる - Qiita
- Named typeclasses in Haskell
- 抽象型クラスで型クラスの変更の非互換性を緩和する - Qiita
- 型クラスのご紹介 - molecular coordinates
- 続くといいな日記 – Coherent Implicit Parameter
- 続くといいな日記 – DerivingVia で deriving 戦略を模倣する
- 多相からプログラミング言語を見る - 趣味はデバッグ……
- Final tagless encodings have little to do with typeclasses – Foxhound Systems
- Deconstructing classes - Tweag
- Deferred Derivation
代数的な型クラス
Ord
Num
- Haskell の Num クラスに対する不満
- tonyday567/numhask - A haskell numeric prelude, providing a clean structure for numbers and operations that combine them.
Semigroup
Monoid
- Haskell Monoids and their Uses
- Monoids and Finger Trees
- Monoids and their efficiency in practice
- Algebraic patterns - Identity element
- Algebraic patterns - Monoid
- Electoral vote distributions are Monoids
- Electoral vote distributions are polynomials
- Monoids on Steroids | Bartosz Milewski’s Programming Cafe
- Monoids: what they are, why they are useful, and what they teach us about software
- An Introduction to Monoids
- Haskell for all: The wizard monoid
- Monoidal Sorting
- Comprehending Monoids with Class
- Monoid と DerivingVia - Qiita
- United Monoids | no time
- Magical Monoids – Ceci n’est pas une pile. – Medium
- Ap Monoid
lists are not free monoids in Haskell.
Formatting
format ("Person's name is " % text % ", age is " % hex) "Dave" 54