Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

AlexandruIca/monads-in-cpp

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Monads in C++

Using coroutines we can say something like:

auto f() -> result<int, std::string>
{
    return "Error!";
}

auto g() -> result<int, std::string>
{
    return 5;
}

auto compute() -> result<int, std::string>
{
    int const a = co_await f();
    int const b = co_await g();

    co_return a + b;
}

What? Why?

I think there's only two possible reactions to this, no in-between:

  • WTF is this?
  • Such a shame there is no direct support from the language for something like this

Building

There is a shell.nix that gives you an environment with all the stuff needed to run this "project"(though you don't need nix, it's just convenient to use). If you have nix you can:

nix-shell

./scripts/build.sh

And then in build/src/ you can run ./cpp-monads.

Resources

Most of this was inspired from here and here.

About

Implementing monads in C++ with coroutines

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.