haskell - In the lets-lens tutorial, how do you refactor out the call to traverse in order to implement over? -
in the exercises have implemented fmapt : -- let's remind ourselves of traversable, noting foldable , functor. -- -- class (foldable t, functor t) => traversable t -- traverse :: -- applicative f => -- (a -> f b) -- -> t -- -> f (t b) -- | observe @fmap@ can recovered @traverse@ using @identity@. -- -- /reminder:/ fmap :: functor t => (a -> b) -> t -> t b fmapt :: traversable t => (a -> b) -> t -> t b fmapt = error "todo: fmapt" now how implement over ? -- | let's refactor out call @traverse@ argument @fmapt@. on :: ((a -> identity b) -> s -> identity t) -> (a -> b) -> s -> t on = error "undefined" you can implement fmapt using traverse as: fmapt f s = runidentity (traverse (identity . f) s) now next exercise refactor function providing traverse parameter rather hard-coding in definition. if choose identity applicative type construct...