[英]Is Data.List.Extra's list function the catamorphism of list?
Haskell's base library contains several functions which are the lowercase versions of their respective data types, like bool
, maybe
and either
. Haskell的基础库包含几个函数,这些函数是各自数据类型的小写版本,例如
bool
, maybe
和either
。 In the source code of Data.Bool.Extra, the bool
function is clearly expressed as the data type's catamorphism: 在Data.Bool.Extra的源代码中,
bool
函数明确表示为数据类型的分类:
bool = curry cata
Now, using the catamorphism as defined in Recursion Schemes by Example , it seems like the above-mentioned base library functions are all the catamorphisms of their data type, eg for Maybe: 现在,使用示例中的递归方案中定义的分类,似乎上述基础库函数都是其数据类型的所有分类,例如对于Maybe:
-- base library definition
maybe n _ Nothing = n
maybe _ f (Just x) = f x
-- definition with cata
newtype Fix f = Fix {unFix :: f (Fix f)}
cata :: Functor f => (f a -> a) -> Fix f -> a
cata alg = alg . fmap (cata alg) . unFix
maybe n f m = cata alg where
alg Nothing = n
alg (Just x) = f x
However, Data.List.Extra's list
function is just mentioned in the comments as a "Non-recursive transform over a list, like 'maybe'", but as it is non-recursive in contrast to its data type, it apparently is not any recursion scheme of list either, or is it? 但是,Data.List.Extra的
list
函数在注释中只是作为“对列表的非递归转换,例如'maybe'”,但由于与数据类型相比是非递归的,因此显然不是列表的任何递归方案,或者是? Is that why it's not defined in the base library? 这就是为什么它没有在基础库中定义吗? Does the function have any other nice theoretical properties?
函数是否还有其他良好的理论特性?
The catamorphism for []
is foldr
. []
的同构是foldr
。
The list
function from the extra
package is a conversion to Scott encoding, in the way that a catamorphism is a conversion to Church encoding. extra
包中的list
函数是对Scott编码的转换,而同形同构是对Church编码的转换。 Since Scott encodings are non-recursive, they can't really correspond to any recursion scheme. 由于Scott编码是非递归的,因此它们不能真正对应于任何递归方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.