Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend Monad for folding over lists #133

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

gfngfn
Copy link

@gfngfn gfngfn commented Jul 2, 2022

The present PR suggests adding the following two values to Base.Monad.S:

val fold_list : f:('a -> 'b -> 'a t) -> init:'a -> 'b list -> 'a t

val map_list : f:('a -> 'b t) -> 'a list -> 'b list t

This will provide implementations of the functions above for modules that implement Monad.Basic such as Option or Result.

The function fold_list roughly corresponds to Haskell’s foldM of Control.Monad and map_list to mapM (though they do not generalize list to any type constructor of class Foldable as foldM and mapM do). As a special case, the newly introduced Result.fold_list corresponds to List.fold_result.

I would appreciate it if you could give any comment or suggestion.

(* PS: I couldn’t guess how to run tests and thereby don’t extend them so far. The following procedure seems promising, but it causes conflicts during the build:

  1. Add (inline_tests) to test/dune,
  2. Remove sexp_grammar from test/dune,
  3. Invoke opam pin add base . at the repository,
  4. Install necessary dependencies, i.e., core v0.15.0 and expect_test_helpers_core, and
  5. Invoke dune test.
$ dune test                            
Error: Conflict between the following libraries:
- "base" in _build/default/src
- "base" in $HOME/.opam/4.12.0/lib/base
  -> required by library "core.base_for_tests" in
     $HOME/.opam/4.12.0/lib/core/base_for_tests
Error: Conflict between the following libraries:
- "base" in _build/default/src
- "base" in $HOME/.opam/4.12.0/lib/base
  -> required by library "ppx_compare.runtime-lib" in
     $HOME/.opam/4.12.0/lib/ppx_compare/runtime-lib

*)

@github-iron github-iron added the forwarded-to-js-devs This report has been forwarded to Jane Street's internal review system. label Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
forwarded-to-js-devs This report has been forwarded to Jane Street's internal review system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants