Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
GHC
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
4,269
Issues
4,269
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
413
Merge Requests
413
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Glasgow Haskell Compiler
GHC
Commits
0670f387
Commit
0670f387
authored
Dec 27, 2020
by
vdukhovni
Committed by
Marge Bot
Jan 09, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New overview of Foldable class
Also updated stale external URL in Traversable
parent
c8c63dde
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
750 additions
and
53 deletions
+750
-53
libraries/base/Data/Foldable.hs
libraries/base/Data/Foldable.hs
+731
-47
libraries/base/Data/Traversable.hs
libraries/base/Data/Traversable.hs
+19
-6
No files found.
libraries/base/Data/Foldable.hs
View file @
0670f387
This diff is collapsed.
Click to expand it.
libraries/base/Data/Traversable.hs
View file @
0670f387
...
...
@@ -82,8 +82,17 @@ import qualified GHC.List as List ( foldr )
-- $setup
-- >>> import Prelude
-- XXX: Missing haddock feature. Links to anchors in other modules
-- don't have a sensible way to name the link within the module itself.
-- Thus, the below "Data.Traversable#overview" works well when shown as
-- @Data.Traversable@ from other modules, but in the home module it should
-- be possible to specify alternative link text. :-(
-- | Functors representing data structures that can be traversed from
-- left to right.
-- left to right, performing an action on each element.
--
-- A more detailed description can be found in the overview section of
-- "Data.Traversable#overview".
--
class
(
Functor
t
,
Foldable
t
)
=>
Traversable
t
where
{-# MINIMAL traverse | sequenceA #-}
...
...
@@ -461,7 +470,9 @@ foldMapDefault = coerce (traverse :: (a -> Const m ()) -> t a -> Const m (t ()))
------------------
-- $overview
-- @Traversable@ functors can be thought of as polymorphic containers that
--
-- #overview#
-- Traversable functors can be thought of as polymorphic containers that
-- support mapping of applicative (or monadic) effects over the container
-- (element-wise) to create a new container of __the same shape__, with the
-- effects sequenced in a natural order for the container type in question.
...
...
@@ -549,6 +560,8 @@ foldMapDefault = coerce (traverse :: (a -> Const m ()) -> t a -> Const m (t ()))
------------------
-- $validation
--
-- #validation#
-- A hypothetical application of the above is to validate a structure:
--
-- >>> validate :: Int -> Either (String, Int) Int
...
...
@@ -581,9 +594,9 @@ foldMapDefault = coerce (traverse :: (a -> Const m ()) -> t a -> Const m (t ()))
-- The @Foldable@ instance should be defined in a manner that avoids
-- construction of an unnecesary copy of the container.
--
--
Perhaps the most widely used @Foldable@ methods are 'mapM_' and its flipp
ed
--
version 'forM_'. Often, to sequence IO actions (that return no useful
--
results) over all the elements of a @Traversable@ container
. One special
--
The @Foldable@ method 'mapM_' and its flipped version 'forM_' can be us
ed
--
to sequence IO actions over all the elements of a @Traversable@ container
--
(just for their side-effects, ignoring any results)
. One special
-- case is a 'Maybe' container that optionally holds a value. Given:
--
-- > action :: a -> IO ()
...
...
@@ -838,7 +851,7 @@ foldMapDefault = coerce (traverse :: (a -> Const m ()) -> t a -> Const m (t ()))
-- * [1] \"The Essence of the Iterator Pattern\",
-- by Jeremy Gibbons and Bruno Oliveira,
-- in /Mathematically-Structured Functional Programming/, 2006, online at
-- <http://w
eb.comlab.ox.ac.uk/oucl/work
/jeremy.gibbons/publications/#iterator>.
-- <http://w
ww.cs.ox.ac.uk/people
/jeremy.gibbons/publications/#iterator>.
--
-- * \"Applicative Programming with Effects\",
-- by Conor McBride and Ross Paterson,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment