"Empty" 可遍历 - 它是否有意义,是否在任何图书馆中提供?

"Empty" traversable - does it make sense, is it provided in any library?

我正在编写一段使用 Traversable 抽象的 Haskell 代码。在这个抽象的背后,我希望能够隐藏所有常规的可遍历结构,如列表、树、地图等,特殊情况 Data.Functor.Identity.Identity 作为包含单个值的基本结构。我还想介绍一个 "empty" 结构的案例。这样的 "empty" 可遍历实例是否存在?也许它已经被任何图书馆提供了?

我第一次(也许是幼稚的)尝试定义这样的实例如下。有道理吗?

data Empty a = Empty

instance Functor Empty where
    fmap _ _ = Empty

instance Foldable Empty where
    foldr _ init _ = init

instance Traversable Empty where
    sequenceA _ = pure Empty

base 中的类型而言,Proxy is precisely that. Const () would also work. (There is also U1,但这是泛型机制的一部分,在其他情况下可能感觉有点不合适。 )