In Haskell, why isn't there a TypeClass for things that can act like lists?

后端 未结 6 954
刺人心
刺人心 2020-12-04 17:59

I\'m reading Learn You a Haskell and I\'m wondering why so many things are acting like a list, and nothing in the Prelude is using the native facility of type classes to set

6条回答
  •  执笔经年
    2020-12-04 18:18

    There are the two type classes called Foldable and Traversable which aim to abstract some common1 behaviours of lists and other sequential data structures. Not all data structures have instances of these though, and I don't know if they are transparent enough to the compiler such that it can still perform optimisation on them (does anybody know something about that?)

    Source: Foldable and Traversable
    See also this answer to Why is Haskell missing “obvious” Typeclasses

提交回复
热议问题