Monadic Operations in Modern C++: A Practical Approach
Monadic Operations in Modern C++: A Practical Approach2About me ● Vitaly Fanaskov ● Senior software engineer at reMarkable ● 10+ years of C++ experience ● GIS, VFX, frameworks, and libraries ● Ph Ph.D (CS) 3Agenda ● Briefly about expected and optional ● Common use cases of expected ● Monadic operations in software development ● Tips and tricks 4In this talk ● Less theory ● C++ only ● Practical log("Cannot get a new widget {}: {}.", widgetBox.value(), error); } } 22How do we handle this? 23Monadic operations: and_then if (const auto widgetBox = getNewWidget(); widgetBox.has_value()) { const0 码力 | 61 页 | 411.49 KB | 5 月前3Pipeline Architectures in C++: Overloaded Pipe Operator | and Its Monadic Operations
on. Title: Pipeline architectures in C++: overloaded pipe operator | std::expected and its monadic operations Brief overview: Functional programming in C++ is gaining importance and is attracting custom pipe operator | will be presented, as well as I’ll explain std::expected and especially its monadic operations that can be tricky in practice. All these together present novel and efficient programming pipelines. What's more, std::expected itself allows you to build pipelines – this time using its monadic operations. In this poseter I will explain details how to build your own pipeline architecture in0 码力 | 3 页 | 422.24 KB | 5 月前3Leveraging a Functional Approach for More Testable and Maintainable ROS 2 Code
Code */ }Monadic Error Handling ● Monadic error handling is a functional programming technique for dealing with errors in a clean, compositional, and type-safe wayMonadic Error Handling ● Monadic error approach encapsulates error handling into types and operations on these typesMonadic Error Handling ● Monadic error handling is a functional programming technique for dealing with errors in a clean, compositional encapsulates error handling into types and operations on these types ● Why is this desirable?Monadic Error Handling ● Monadic error handling is a functional programming technique for dealing with errors in a clean0 码力 | 200 页 | 1.77 MB | 5 月前3C++23: An Overview of Almost All New and Updated Features
basic_string(_view)::contains() Construct string(_view) From nullptr basic_string::resize_and_overwrite() Monadic Operations for std::optional Stacktrace Library Changes to Ranges Library Changes to Views basic_string(_view)::contains() Construct string(_view) From nullptr basic_string::resize_and_overwrite() Monadic Operations for std::optional Stacktrace Library Changes to Ranges Library Changes to Views basic_string(_view)::contains() Construct string(_view) From nullptr basic_string::resize_and_overwrite() Monadic Operations for std::optional Stacktrace Library Changes to Ranges Library Changes to Views0 码力 | 105 页 | 759.96 KB | 5 月前3Applicative: The Forgotten Functional Pattern
m b) -> m a -> m b -- bind with flipped args (>>=) :: m a -> (a -> m b) -> m b 16MONADIC FUNCTIONS FOR MONADIC FUNCTIONS FOR std::optional std::optional "If "If *this *this contains a value, invokes (this is (this is fmap fmap)) templateconstexpr auto transform(F&& f); 17MONADIC FUNCTIONS FOR MONADIC FUNCTIONS FOR std::optional std::optional "If "If *this *this contains a value, invokes and Monad. Every Monad is also an Applicative. And Functorial/Monadic patterns show up in C++ sometime post C++11. And Functorial/Monadic patterns show up in C++ sometime post C++11. 21PART 2 PART 2 0 码力 | 141 页 | 11.33 MB | 5 月前3DEDUCING this PATTERNS
sorts) Mid 2013: I start playing with monadic futures. I run into a problem.FIRST, AN ORIGIN STORY (and timeline of sorts) Mid 2013: I start playing with monadic futures. I run into a problem. May 2014: for the first time.FIRST, AN ORIGIN STORY (and timeline of sorts) Mid 2013: I start playing with monadic futures. I run into a problem. May 2014: I go to C++Now for the first time. May 2015: I go back to about the problem.FIRST, AN ORIGIN STORY (and timeline of sorts) Mid 2013: I start playing with monadic futures. I run into a problem. May 2014: I go to C++Now for the first time. May 2015: I go back to0 码力 | 126 页 | 5.15 MB | 5 月前3Haskell 2010 Language Report
. . . . . . . . . . . 158 13.2.4 Conditional execution of monadic expressions . . . . . . . . . . . . . . . . . . . . 159 13.2.5 Monadic lifting operators . . . . . . . . . . . . . . . . . . . . . typing, user-defined algebraic datatypes, pattern-matching, list comprehensions, a module system, a monadic I/O system, and a rich set of primitive datatypes, including lists, arrays, arbitrary and fixed precision exp ; | let decls ; | ; (empty statement) A do expression provides a more conventional syntax for monadic programming. It allows an expression such as putStr "x: " >> getLine >>= \l -> return (words l)0 码力 | 329 页 | 1.43 MB | 1 年前3Monads in Modern C++
wrapping monadic type, monads define two operators: one to wrap a value in the monad type, and another to compose together functions that output values of the monad type (these are known as monadic functions) wrapping monadic type, monads define two operators: one to wrap a value in the monad type, and another to compose together functions that output values of the monad type (these are known as monadic functions) • All the requirements of functor, plus one more operation • The operation is typically called monadic bind or mbind. In C++: and_then • Can be thought of as a transform, followed by a join 44 template0 码力 | 94 页 | 4.56 MB | 5 月前3Modern C++ Error Handling
Error: passed string is not a number Error: Divide by zerostd::expected and std::optional C++23 monadic operations for0.024390243 Error: passed string is not a number Error: Divide by zero void t Out param Global/ TL variable Boost Leaf? Exceptions optional/ expected Raw Raw in lambda Monadic operations assert Policy-based Checking Checked/ unchecked versions Correct-by-construction0 码力 | 66 页 | 36.65 MB | 5 月前3Compile-Time Validation
access can throw result.value(); result.error();Monadic Operations Safely access the wrapped result value. The context type can change between monadic operations. std::expectedresult = foo(); 0 码力 | 137 页 | 1.70 MB | 5 月前3
共 49 条
- 1
- 2
- 3
- 4
- 5