8000 gh-5 misc: Merge pull request #6 from AlexandruIca/gh-5-Add-README-an… · AlexandruIca/monads-in-cpp@ee148dd · GitHub
[go: up one dir, main page]

Skip to content

Commit ee148dd

Browse files
authored
gh-5 misc: Merge pull request #6 from AlexandruIca/gh-5-Add-README-and-LICENSE
gh-5 Add README and LICENSE
2 parents 17dd833 + 73e36a1 commit ee148dd

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

LICENSE.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <http://unlicense.org/>

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Monads in C++
2+
Using coroutines we can say something like:
3+
```cpp
4+
auto f() -> result<int, std::string>
5+
{
6+
return "Error!";
7+
}
8+
9+
auto g() -> result<int, std::string>
10+
{
11+
return 5;
12+
}
13+
14+
auto compute() -> result<int, std::string>
15+
{
16+
int const a = co_await f();
17+
int const b = co_await g();
18+
19+
co_return a + b;
20+
}
21+
```
22+
23+
# What? Why?
24+
I think there's only two possible reactions to this, no in-between:
25+
* WTF is this?
26+
* Such a shame there is no direct support from the language for something like this
27+
28+
# Building
29+
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:
30+
```sh
31+
nix-shell
32+
33+
./scripts/build.sh
34+
```
35+
And then in `build/src/` you can run `./cpp-monads`.
36+
37+
# Resources
38+
Most of this was inspired from [here](https://www.reddit.com/r/cpp/comments/6ly4rz/it_had_to_be_done_abusing_co_await_for_optionals/) and [here](https://cpp-rendering.io/c-error-handling-lets-abuse-the-co_await-operator/).

0 commit comments

Comments
 (0)
0