summaryrefslogtreecommitdiff
path: root/libraries/base/Control/Monad.hs
Commit message (Collapse)AuthorAgeFilesLines
* Fix a few Note inconsistenciesBen Gamari2022-02-011-2/+1
|
* Change replicateM doctest exampleOleg Grenrus2021-01-221-4/+13
|
* Remove references to ApplicativeDo in the base haddocksHécate2021-01-131-26/+11
|
* Correct doctestsOleg Grenrus2021-01-021-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's simpler to assume that base is NoImplicitPrelude, otherwise running doctest on `GHC.*` modules would be tricky. OTOH, most `GHC.List` (where the most name clashes are) examples could be changed to use `import qualified Data.List as L`. (GHC.List examples won't show for Foldable methods...). With these changes majority of doctest examples are GHCi-"faithful", my WIP GHC-independent doctest runner reports nice summary: Examples: 582; Tried: 546; Skipped: 34; Success: 515; Errors: 33; Property Failures 2 Most error cases are *Hangs forever*. I have yet to figure out how to demonstrate that in GHCi. Some of divergences are actually stack overflows, i.e. caught by runtime. Few errorful cases are examples of infinite output, e.g. >>> cycle [42] [42,42,42,42,42,42,42,42,42,42... while correct, they confuse doctest. Another erroneous cases are where expected output has line comment, like >>> fmap show (Just 1) -- (a -> b) -> f a -> f b Just "1" -- (Int -> String) -> Maybe Int -> Maybe String I think I just have to teach doctest to strip comments from expected output. This is a first patch in a series. There is plenty of stuff already.
* Added do-notation examples for Functor, Applicative and Monad combinators.Baldur Blöndal2019-07-201-0/+32
|
* base: Include (<$) in all exports of FunctorSimon Jakobi2019-05-271-1/+1
| | | | | | | Previously the haddocks for Control.Monad and Data.Functor gave the impression that `fmap` was the only Functor method. Fixes #16681.
* base: Remove `Monad(fail)` method and reexport `MonadFail(fail)` insteadHerbert Valerio Riedel2019-03-221-1/+3
| | | | | | As per https://prime.haskell.org/wiki/Libraries/Proposals/MonadFail Coauthored-by: Ben Gamari <ben@well-typed.com>
* Update Trac ticket URLs to point to GitLabRyan Scott2019-03-151-2/+2
| | | | | This moves all URL references to Trac tickets to their corresponding GitLab counterparts.
* base: Allow fusion for zip7 and relatedAlexandre2019-02-241-0/+2
| | | | | | | | | | | | | | | | | | Fixes #14037. Metric Decrease: T9872b T9872d Reviewers: bgamari, simonpj, hvr Reviewed By: simonpj Subscribers: AndreasK, simonpj, osa1, dfeuer, rwbarton, carter GHC Trac Issues: #14037 Differential Revision: https://phabricator.haskell.org/D5249
* Add comments about how zip fusionSimon Peyton Jones2019-02-201-0/+4
| | | | | | Alexandre Balde (rockbmb) points out that the fusion technology for foldr2, zip, zipWith, etc is undocumented. This patch adds comments to explain.
* docs: "state transformer" -> "state monad" / "ST" (whichever is meant)Artem Pelenitsyn2018-08-211-1/+1
| | | | | | | | | | | | | | FIxes #15189. Reviewers: hvr, bgamari, simonmar, simonpj Reviewed By: simonpj Subscribers: simonpj, rwbarton, thomie, carter GHC Trac Issues: #15189 Differential Revision: https://phabricator.haskell.org/D5019
* Fix ambiguous/out-of-scope Haddock identifiersAlec Theriault2018-08-211-2/+2
| | | | | | | | | | | | | | | | | This drastically cuts down on the number of Haddock warnings when making docs for `base`. Plus this means more actual links end up in the docs! Also fixed other small mostly markup issues in the documentation along the way. This is a docs-only change. Reviewers: hvr, bgamari, thomie Reviewed By: thomie Subscribers: thomie, rwbarton, carter Differential Revision: https://phabricator.haskell.org/D5055
* Tweak wording in documentationVictor Nawothnig2018-06-191-2/+3
| | | | | | | | Reviewers: hvr, bgamari Subscribers: rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4871
* Fix mistaken mergeBen Gamari2018-01-121-22/+15
| | | | | | | When merging D4259 I had to resort to manual merge due to some conflicts that arc couldn't sort out. Unfortunately in the process I merged the wrong version of the patch. Fix this. Thanks to @ntc2 for the great documentation and noticing my mistake.
* Improve Control.Monad docsNathan Collins2018-01-021-1/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: * Reformat Control.Monad.mfilter docs The formatting was bad, with everything running together, and a paranthesis was missing. Now the examples and relation between `filter` and `mfilter` are typeset as code blocks instead of inline. * Add example to Control.Monad.join docs The example is using `join . atomically` to run IO actions computed by STM transactions. I couldn't figure out how to link to the STM docs in `Control.Monad.STM`, because that module comes from the `stm` package, not from `base`, even though `stm` is also part of the GHC source tree. So, instead I linked to the STM docs in `GHC.Conc`, which seems inferior to linking to `Control.Monad.STM`, but better than having no links at all. * Add example to Control.Monad.forever docs The example is a simple TCP echo server. To make the uses of `forever` stand out in the example code, I only link to the non-`forever` functions (e.g. `forkFinally`) in the import lists. Reviewers: bgamari, hvr Subscribers: rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4259
* Reformat Control.Monad.mfilter docsNathan Collins2018-01-021-6/+19
| | | | | | The formatting was bad, with everything running together, and a paranthesis was missing. Now the examples and relation between `filter` and `mfilter` are typeset as code blocks instead of inline.
* Improve Control.Monad.guard and Control.Monad.MonadPlus docsNathan Collins2017-12-111-2/+41
| | | | | | | | | | | | | This fixes Issue #12372: documentation for Control.Monad.guard not useful after AMP. Reviewers: hvr, bgamari Reviewed By: bgamari Subscribers: rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4258
* change example from msum to mfilterJulie Moronuki2017-11-031-2/+2
|
* Loads of doc(test)sDavid Luposchainsky2017-08-171-15/+15
|
* Typos in comments and manualGabor Greif2017-03-061-1/+1
|
* Replace INLINEABLE by INLINABLE (#12613)Joachim Breitner2016-09-241-6/+6
| | | | | | | | | | as the latter is the official, correct spelling, and the former just a misspelling accepted by GHC. Also document in the user’s guide that the alternative spelling is accepted This commit was brough to you by HIW 2016.
* Typos in NoteJoachim Breitner2016-04-101-8/+5
|
* Add doc to (<=<) comparing its type to (.)Chris Martin2016-04-101-1/+6
| | | | | | | | | | | | | | This is another documentation addition similar to D1989, this time comparing the type of the Kleisli composition operator (<=<) to that of plain function composition (.). Reviewers: hvr, austin, bgamari Reviewed By: bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2100
* Provide an optimized replicateM_ implementation #11795Michael Snoyman2016-04-101-5/+38
| | | | | | | | | | | | | | | | | | In my testing, the worker/wrapper transformation applied here significantly decreases the number of allocations performed when using replicateM_. Additionally, this version of the function behaves correctly for negative numbers (namely, it will behave the same as replicateM_ 0, which is what previous versions of base have done). Reviewers: bgamari, simonpj, hvr, austin Reviewed By: bgamari, simonpj, austin Subscribers: nomeata, simonpj, mpickering, thomie Differential Revision: https://phabricator.haskell.org/D2086 GHC Trac Issues: #11795
* MonadFail proposal, phase 1David Luposchainsky2015-11-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | This implements phase 1 of the MonadFail proposal (MFP, #10751). - MonadFail warnings are all issued as desired, tunable with two new flags - GHC was *not* made warning-free with `-fwarn-missing-monadfail-warnings` (but it's disabled by default right now) Credits/thanks to - Franz Thoma, whose help was crucial to implementing this - My employer TNG Technology Consulting GmbH for partially funding us for this work Reviewers: goldfire, austin, #core_libraries_committee, hvr, bgamari, fmthoma Reviewed By: hvr, bgamari, fmthoma Subscribers: thomie Projects: #ghc Differential Revision: https://phabricator.haskell.org/D1248 GHC Trac Issues: #10751
* Weaken monadic list operations to ApplicativeBen Gamari2015-11-161-22/+20
| | | | | | | | | | | | | | | | | Generalize `filterM`, `mapAndUnzipM`, `zipWithM`, `zipWithM_`, `replicateM`, and `replicateM_`. Reviewers: ekmett, #core_libraries_committee, austin, hvr, bgamari Reviewed By: ekmett, #core_libraries_committee, bgamari Subscribers: ekmett, glguy, thomie Projects: #ghc Differential Revision: https://phabricator.haskell.org/D1324 GHC Trac Issues: #10168
* Generalize `Control.Monad.forever`Ben Gamari2015-07-071-2/+2
| | | | | | | | | This generalizes forever to depend on Applicative, rather than Monad. This was proposed a month ago (https://mail.haskell.org/pipermail/libraries/2015-May/025711.html). Differential Revision: https://phabricator.haskell.org/D1045
* Convert `/Since: .../` to new `@since ...` syntaxHerbert Valerio Riedel2014-12-161-1/+1
| | | | | | Starting with Haddock 2.16 there's a new built-in support for since-annotations Note: This exposes a bug in the `@since` implementation (see e.g. `Data.Bits`)
* Generalise `Control.Monad.{foldM,foldM_}` to `Foldable` (#9586)Herbert Valerio Riedel2014-10-181-6/+7
| | | | | | | | | With this change `Control.Monad.foldM` becomes an alias for `Data.Foldable.foldlM`. Reviewed By: austin, ekmett Differential Revision: https://phabricator.haskell.org/D251
* Make filterM a good consumerDavid Feuer2014-10-011-5/+7
| | | | analogously to mapM. Fixes #9546.
* Generalise `guard` for real this timeHerbert Valerio Riedel2014-09-281-1/+1
| | | | This was missed in D253 / a07ce1654ac5b8033f2daf9270c6e182415b69ca
* Generalise `Control.Monad.{when,unless,guard}`Herbert Valerio Riedel2014-09-281-6/+6
| | | | | | | | | | | | Generalise `when`/`unless`from `Monad` to `Applicative` and `guard` from `MonadPlus` to `Alternative` respectively. This was made possible by the AMP and is somewhat related to #9586 (but generalising in the context of the AMP instead of the FTP) Reviewed By: ekmett, austin Differential Revision: https://phabricator.haskell.org/D253
* Don't re-export `Alternative(..)` from Control.Monad (re #9586)Herbert Valerio Riedel2014-09-261-1/+0
| | | | | | | | | | | | | | | | | This was done in d94de87252d0fe2ae97341d186b03a2fbe136b04 to avoid orphans but since a94dc4c3067c6a0925e2e39f35ef0930771535f1 moved `Alternative` into GHC.Base, this isn't needed anymore. This is important, as otherwise this would require a non-neglectable amount of `Control.Monad hiding ((<|>), empty)` imports in user code. The Haddock submodule is updated as well Test Plan: partial local ./validate --fast, let Harbormaster doublecheck it Reviewed By: ekmett, austin Differential Revision: https://phabricator.haskell.org/D248
* `M-x delete-trailing-whitespace` & `M-x untabify`Herbert Valerio Riedel2014-09-241-7/+7
| | | | ...several modules in `base` recently touched by me
* Generalise Data.List/Control.Monad to Foldable/TraversableHerbert Valerio Riedel2014-09-211-7/+2
| | | | | | | | | | | | | | | | | | | | | | | | | This flips the switch and replaces the entities in `Data.List`/`Control.Monad` conflicting with `Data.{Foldable,Traversable}` with re-exports of the more general versions. As of this commit, the code below (which is also added as a test-case) compiles w/o error. module XPrelude (module X) where import Control.Monad as X import Data.Foldable as X import Data.List as X import Data.Monoid as X import Data.Traversable as X import Prelude as X This addresses #9568 Reviewed By: ekmett, austin Differential Revision: https://phabricator.haskell.org/D235
* Move `mapM` and `sequence` to GHC.Base and break import-cyclesHerbert Valerio Riedel2014-09-211-16/+1
| | | | | | | | | | This simplifies the import graph and more importantly removes import cycles that arise due to `Control.Monad` & `Data.List` importing `Data.Traversable` (preparation for #9586) Reviewed By: ekmett, austin Differential Revision: https://phabricator.haskell.org/D234
* Generalise Control.Monad.{sequence_,msum,mapM_,forM_}Herbert Valerio Riedel2014-09-181-25/+2
| | | | | | | | | | | | | | | | This finally takes the gloves off, and performs the first actual generalization in order to implement #9586. This re-exports the respective definitions for the 4 combinators defined in Data.Foldable. This way, importing Data.Foldable and Control.Monad unqualified won't bring conflicting definitions of those 4 entities into scope anymore. This change seems to have some minor effect on rule-firing, which causes some wibble in the test-case T4007 Reviewed By: ekmett, austin Differential Revision: https://phabricator.haskell.org/D226
* Invert module-dep between Control.Monad and Data.FoldableHerbert Valerio Riedel2014-09-181-0/+1
| | | | | | | | | This is the last preparation needed before generalizing entities in Control.Monad conflicting with those from Data.Foldable (re #9586) Reviewed By: ekmett, austin Differential Revision: https://phabricator.haskell.org/D225
* Move Control.Monad.void into Data.FunctorHerbert Valerio Riedel2014-09-181-4/+1
| | | | | | | | | | | | Both modules still export `void`, but `void`'s implementation now lives in Data.Functor where it actually belongs in (as it doesn't need a Monad context) The desired side-effect of this is to invert the import-dep between Control.Monad and Data.Functor. Reviewed By: ekmett, austin Differential Revision: https://phabricator.haskell.org/D224
* Move Applicative/MonadPlus into GHC.BaseHerbert Valerio Riedel2014-09-181-72/+0
| | | | | | | | | | | This is necessary in order to invert the import-dependency between Data.Foldable and Control.Monad (for addressing #9586) This also updates the `binary` submodule to qualify a GHC.Base import Reviewed By: austin Differential Revision: https://phabricator.haskell.org/D223
* Move `when` to GHC.BaseHerbert Valerio Riedel2014-09-181-15/+0
| | | | | | | | | This allows several modules to avoid importing Control.Monad and thus break import cycles that manifest themselves when implementing #9586 Reviewed By: austin, ekmett Differential Revision: https://phabricator.haskell.org/D222
* Move (=<<) to GHC.BaseHerbert Valerio Riedel2014-09-181-6/+0
| | | | | | | | | This allows GHC.Stack to avoid importing Control.Monad, and is preparatory work for implementing #9586 Reviewed By: austin Differential Revision: https://phabricator.haskell.org/D221
* base: replace ver 4.7.1.0 references by 4.8.0.0Herbert Valerio Riedel2014-09-091-1/+1
| | | | | | | Since we now had to major bump due to AMP being landed, `base-4.7.1.0` is not gonna happen, as we're going straight for a `base-4.8.0.0` release. [skip ci] since this is a doc-only change
* Make Applicative a superclass of MonadAustin Seipp2014-09-091-73/+53
| | | | | | | | | | | | | | | | | | | | | Summary: This includes pretty much all the changes needed to make `Applicative` a superclass of `Monad` finally. There's mostly reshuffling in the interests of avoid orphans and boot files, but luckily we can resolve all of them, pretty much. The only catch was that Alternative/MonadPlus also had to go into Prelude to avoid this. As a result, we must update the hsc2hs and haddock submodules. Signed-off-by: Austin Seipp <austin@well-typed.com> Test Plan: Build things, they might not explode horribly. Reviewers: hvr, simonmar Subscribers: simonmar Differential Revision: https://phabricator.haskell.org/D13
* Specialise monad functions, and make them INLINEABLESimon Peyton Jones2014-08-281-0/+38
| | | | | Specialise liftM, foldM, etc, and make them specialisable for new monads at their call sites by using INLINEABLE
* Add strict ver. of (<$>): (<$!>) to Control.MonadAlexander Berntsen2014-05-141-0/+15
| | | | | | | | | | | | | | | A strict (<$>) has been proposed numerous times. The first time around[1] by Johan Tibell, and the last time around[2] by David Luposchainsky. David's thread was able to avoid The Bikeshed Monster, and his (<$!>) proposal received unanimous +1s all around. This addresses #9099. [1]: http://www.haskell.org/pipermail/libraries/2013-November/021728.html [2]: http://www.haskell.org/pipermail/libraries/2014-April/022864.html Authored-by: Alexander Berntsen <alexander@plaimi.net> Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Constant-fold `__GLASGOW_HASKELL__` CPP conditionalsHerbert Valerio Riedel2013-09-171-6/+1
| | | | | | | | | | Now that HUGS and NHC specific code has been removed, this commit "folds" the now redundant `#if((n)def)`s containing `__GLASGOW_HASKELL__`. This renders `base` officially GHC only. This commit also removes redundant `{-# LANGUAGE CPP #-}`. Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Remove commented types in module export listsIan Lynagh2012-10-271-33/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These comments are rather less useful now that haddock can give docs with the same informatino in the module synopsis. Having to maintain them when making changes to the library is a pain, and when people forget about doing so there is nothing that checks that the comments are right, so mistakes tend to linger. Of the comments that my script detected, 78 of 684 were already incorrect in one way or another, e.g. missing context: Text.Show.showsPrec Comment type: Int -> a -> ShowS Actual type: Show a => Int -> a -> ShowS wrong context: Numeric.readInt Comment type: Integral a => a -> (Char -> Bool) -> (Char -> Int) -> ReadS a Actual type: Num a => a -> (Char -> Bool) -> (Char -> Int) -> ReadS a not following a class change (e.g. Num losing its Eq superclass): Text.Read.Lex.readOctP Comment type: Num a => ReadP a Actual type: (Eq a, Num a) => ReadP a not following the Exceptions change: GHC.Conc.childHandler Comment type: Exception -> IO () Actual type: SomeException -> IO () or just always been wrong: GHC.Stable.deRefStablePtr Comment type: StablePtr a -> a Actual type: StablePtr a -> IO a
* Improve definition of forever (#5205)Paolo Capriotti2012-08-201-19/+4
| | | | | | | | | | | | | | The previous implementation was: forever a = a >> forever a which can create a space leak in some cases, even with optimizations. The current implementation: forever a = let a' = a >> a' in a' prevents repeated thunk allocations by creating a single thunk for the final result, even without optimizations.
* SafeHaskell: Added SafeHaskell to baseDavid Terei2011-06-181-0/+1
|