The Fold a b type represents a left-fold, which means that it is isomorphic to functions of type [a] -> b (assuming the input list is finite). The profunctors package now has typeclasses to represent this isomorphism:
instance Cosieve Fold [] where
cosieve = fold
instance Corepresentable Fold where
type Corep Fold = []
cotabulate f = fmap f list
instance Costrong Fold where
unfirst = unfirstCorep
-- Laws
-- 1. cosieve . cotabulate == id :: ([a] -> b) -> [a] -> b
-- cosieve (cotabulate f) xs == f xs
-- fold (fmap f list) xs == f xs
-- F.foldr (\a k x -> k $ x . (a:)) (f . ($ [])) xs id == f xs
-- (f . ($ [])) (F.foldl (\k a -> k . (a:)) id xs) == f xs
-- f (F.foldl (\k a -> k . (a:)) id xs []) == f xs
-- f xs == f xs
--
-- 2. cotabulate . cosieve == id :: Fold a b
-- cotabulate (cosieve f) == f
-- fmap (fold f) list == f
-- f == f
Currently, foldl only requires profunctors >= 3.2, with Corepresentable added in profunctors 4.0 and Costrong in 4.3.2, so this addition would require changing the version bounds or adding preprocessor checks.
The
Fold a b
type represents a left-fold, which means that it is isomorphic to functions of type[a] -> b
(assuming the input list is finite). Theprofunctors
package now has typeclasses to represent this isomorphism:Currently,
foldl
only requiresprofunctors >= 3.2
, withCorepresentable
added inprofunctors 4.0
andCostrong
in4.3.2
, so this addition would require changing the version bounds or adding preprocessor checks.