Why is Haskell missing “obvious” Typeclasses

前端 未结 7 1886
南笙
南笙 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:06

    The lens package provides some of this.

    • Testing for emptiness, creating empty containers These are both provided by the AsEmpty typeclass from Control.Lens.Empty.

    • Accessing elements by key/index. The At and Ixed typeclasses from Control.Lens.At.

    • Checking for membership in set-like containers. The Contains typeclass from Control.Lens.At.

    • Appending and deleting elements to sequence-like containers. The Cons and Snoc typeclasses from Control.Lens.Cons.

    Also, the pure method of the Applicative typeclass can often be used to create "singleton" containers. For things that are not functors/applicatives in Haskell, like Set, perhaps point from Data.Pointed could be used.

提交回复
热议问题