You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Naturality: t . traverse f = traverse (t . f). Transforming the final outer layer is the same as transforming the produced structure on the inside before swapping the types.
Identity: traverse Identity = Identity. Traversable doesn't add or inject any structure / context.
Composition: traverse (Compose . fmap g . f) = Compose . fmap (traverse g) . traverse f. "…we can collapse sequential traversals into a single traversal, by taking advantage of the Compose datatype, which combines structure."
These laws can be expressed via sequenceA but it's just another formulation, neither prettier nor uglier IMHO.
traversable::forallfabm.
( Traversablef, Monoidm, Show (fa)
, Arbitrary (fa), Arbitraryb, Arbitrarya, Arbitrarym
, CoArbitrarya
, EqProp (fb), EqPropm) =>f (a, b, m) ->TestBatch
traversable =const ( "traversable"
, [ ("fmap", property fmapP)
, ("foldMap", property foldMapP)
]
)
wherefmapP:: (a->b) ->fa->PropertyfoldMapP:: (a->m) ->fa->Property
fmapP f x = f `fmap` x =-= f `fmapDefault` x
foldMapP f x = f `foldMap` x =-= f `foldMapDefault` x
Perhaps I am misreading this or not reasoning through it all the way, but it doesn't seem to me that this is enforcing all the laws, explicitly or implicitly.
Follow up: does this link imply that if fmap and foldMap can be recovered, then the laws must hold? It seems the other way around to me, that if the laws hold, fmap and foldMap can be recovered. I don't know enough to state this definitively, but the implication arrow doesn't seem to be symmetric here, i.e. I don't know if this is an "if and only if" relationship.
The text was updated successfully, but these errors were encountered:
glebec
changed the title
traversable laws?
Traversable laws?
Sep 22, 2018
It doesn't appear as if
checkers
actually enforces all theTraversable
laws, which include (as per http://haskellbook.com):t . traverse f = traverse (t . f)
. Transforming the final outer layer is the same as transforming the produced structure on the inside before swapping the types.traverse Identity = Identity
. Traversable doesn't add or inject any structure / context.traverse (Compose . fmap g . f) = Compose . fmap (traverse g) . traverse f
. "…we can collapse sequential traversals into a single traversal, by taking advantage of theCompose
datatype, which combines structure."These laws can be expressed via
sequenceA
but it's just another formulation, neither prettier nor uglier IMHO.The current check just runs:
Perhaps I am misreading this or not reasoning through it all the way, but it doesn't seem to me that this is enforcing all the laws, explicitly or implicitly.
Follow up: does this link imply that if
fmap
andfoldMap
can be recovered, then the laws must hold? It seems the other way around to me, that if the laws hold,fmap
andfoldMap
can be recovered. I don't know enough to state this definitively, but the implication arrow doesn't seem to be symmetric here, i.e. I don't know if this is an "if and only if" relationship.The text was updated successfully, but these errors were encountered: