我工作的数据库操作哈斯克尔荟萃-SQL语言,并在普通型类库去用它,从Hackage恶癖无论它是有道理的。Data.Foldable无序容器
因为数据库查询优化器的显著目标是消除不必要的排序,它保存在哪里排序是必要的其实是一个静态表示是很重要的。这给我们定义了一个折叠类型类。
Haskell的Data.Foldable
有:(eliding默认定义,这是不相关的一点,我正在做)
class Foldable t where
-- | Combine the elements of a structure using a monoid.
fold :: Monoid m => t m -> m
-- | Map each element of the structure to a monoid,
-- and combine the results.
foldMap :: Monoid m => (a -> m) -> t a -> m
-- | Right-associative fold of a structure.
foldr :: (a -> b -> b) -> b -> t a -> b
-- | Left-associative fold of a structure.
foldl :: (a -> b -> a) -> a -> t b -> a
-- | A variant of 'foldr' that has no base case,
-- and thus may only be applied to non-empty structures.
foldr1 :: (a -> a -> a) -> t a -> a
-- | A variant of 'foldl' that has no base case,
-- and thus may only be applied to non-empty structures.
foldl1 :: (a -> a -> a) -> t a -> a
在我看来,这个类忽略了区别是,出于实用的目的,不对大多数Haskell应用程序非常重要,但对数据库设置更感兴趣。即:所有Data.Foldable
实例都附带一个排序。
,这是什么概念,适用于不上它们的元素强加顺序容器类型的泛化的名字吗?
对于Haskell Data.Set
它工作正常,因为有一个Ord
上下文需要执行。但是,排序要求是实现人为因素,对于许多有用的类型,使用的排序可能没有任何域级别的含义。
对于更一般来说,fold :: Monoid m => t m -> m
定义本身是大多数是正确的(所以是foldMap
)。我说主要是因为它的类型包括结合性法律(通过Monoid
的定义),但不包括所需的交换法则。其他变体甚至不存在。
我不想引进并不需要的地方排序。我也不想引入非确定性它不能被跟踪。我感兴趣的是建立一种语言,库,不具备toList :: Set a -> [a]
功能随地乱丢,因为它引入了有着天壤之别:
- 让人们看到有关一组/关系是如何物理存储的实现细节
- 失去轨道的非确定性的作为效果
显然既sortBy :: (a -> a -> Ordering) -> Set a -> [a]
和shuffle :: Set a -> Data.Random.RVar [a]
是有用的,无可非议,并且将被包括在内。实际上,sortBy
具有更通用的类型,如sortBy :: (TheUnorderedFoldableClassIAmTryingToName f) => (a -> a -> Ordering) -> f a -> [a]
。
叫什么概念呢?如果我远离基地,我在哪里离开基地路线?