Why is Haskell missing “obvious” Typeclasses

前端 未结 7 1834
南笙
南笙 2020-12-12 22:57

Consider the Object-Oriented Languages:

Most people coming from an object-oriented programming background, are familiar with the common and intuitiv

相关标签:
7条回答
  • 2020-12-12 23:29

    You have typeclasses for different collection aspects:

    1. composition: Monoid (module Data.Monoid)

    2. sequential control: Applicative, Monad (modules Control.Applicative, Control.Monad)

    3. sequential composition: Alternative, MonadPlus (modules Control.Applicative, Control.Monad)

    4. non-sequential mapping and reduction: Functor (mod. Data.Functor), Foldable (mod. Data.Foldable)

    5. sequential mapping and reduction: Traversable (module Data.Traversable)

    6. serialisation: Binary (mod. Data.Binary)

    7. comparison: Eq, Ord (mod. Data.Eq, Data.Ord)

    8. textualisation: Show, Read

    9. deep evaluation (to Normal Form): NFData (mod. Control.DeepSeq)

    10. generic datatype traversability: Data (mod. Data.Data)

    Except that monomorphic collections (ByteString, IntSet, Text) cannot implement Functor and Foldable (they require type arity == 1 (Kind: * -> *))

    Also neither (Set a) implements Functor.

    The package mono-traversable redefines some classes without the monomorphic types exclusion.

    Update. There is an attempt to put most functions in typeclasses with the packages mono-traversable and classy-prelude.

    library ref, platform

    0 讨论(0)
提交回复
热议问题