Monoids, Monads, and Applicative Functors: Repeated Software Patterns - David Sankel - CppCon 2020

  Рет қаралды 24,638

CppCon

CppCon

Күн бұрын

cppcon.org/
github.com/CppCon/CppCon2020
---
Forget factories, singletons, and proxies; What are the real patterns in software development? This talk explores abstract mathematical structures that commonly recur in software development. Once a mind is trained to recognize these patterns, it becomes easy to identify the fundamental operations for domain specific classes and how to put the pieces together. This discussion is for those who enjoy math, abstract concepts, and expanding their minds.
---
David Sankel is a Software Engineering Manager/TL at Bloomberg and an active member of the C++ Standardization Committee. His experience spans microservice architectures, CAD/CAM, computer graphics, visual programming languages, web applications, computer vision, and cryptography. He is a frequent speaker at C++ conferences and specializes in large-scale software engineering and advanced C++ topics. David’s interests include dependently typed languages, semantic domains, EDSLs, and functional reactive programming. He is the project editor of the C++ Reflection TS, a member of the Boost steering committee, and an author of serveral C++ proposals including pattern matching and language variants.
---
Streamed & Edited by Digital Medium Ltd - events.digital-medium.co.uk
events@digital-medium.co.uk
*-----*
Register Now For CppCon 2022: cppcon.org/registration/
*-----*

Пікірлер: 44
@gieseanw
@gieseanw 3 жыл бұрын
Really clever way to handle a remote presentation
@AllForMarketing
@AllForMarketing 3 жыл бұрын
This guy presents on whole new level
@ilikedirt
@ilikedirt 3 жыл бұрын
This was so awesome I want all category theory to be introduced like this.
@youknowwho1686
@youknowwho1686 3 жыл бұрын
Excellent. Sound, presentation, delivery. Very impressive and even entertaining... talking about monads... would never expected. Thank you.
@NonTwinBrothers
@NonTwinBrothers Жыл бұрын
With this presentation style you'll go far
@ericzenk4404
@ericzenk4404 3 жыл бұрын
This video is great. It has category theory and kids answering questions about category theory.
@piliparbotond
@piliparbotond 3 жыл бұрын
Those kids are serious about their computer science knowledge! :)
@DiegoPerini
@DiegoPerini 3 жыл бұрын
Thank you so much David, CppCon and the crew.
@code_report
@code_report 3 жыл бұрын
Best talk of CppCon 2020!
@Krzysztow1985
@Krzysztow1985 3 жыл бұрын
Haha, awesome use of your family! Wonder if they'd be able to sat there through the whole talk. The talk is good too :)
@Yupppi
@Yupppi 5 ай бұрын
Gotta say, Sankel feels so much more restricted when he's not able to walk around the stage while presenting. He's really good at that pacing combined to the presentation based on having seen his other talks. I really enjoy his talks in general, he always has something important and useful to say. This was a weird and different way to visualize the talk but it was funny and effective. But I feel a bit discouraged how Sankel's small kids are much smarter on this than I. Recently I've been trying to expand my views by getting into functional programming and this just hits the spot perfectly. In my opinion monoids and functors and monads don't seem like complicated concepts per se, but there's all this vocabulary abstraction and mathematical "jargon" describing accurately what they do that it becomes just repeating unfamiliar words many times in a sentence, which completely obscures the ability to interpret the concept. Like when showing an example piece of code (preferrably without templating and being general because that messes people up even more) it looks like a familiar action that only had an unfamiliar name and list of rules/specifications you never thought about. Like I swear almost all of us have written a monoid, used a functor, perhaps monadic too. I swear nobody has ever read a formal mathematical description and applied it like that. You write the mathematical description after you've figured out a pattern of sorts and then everybody reads it and you show what you mean and then they start to understand and apply.
@rstar0000
@rstar0000 3 жыл бұрын
Best talk this year by far!
@GrzegorzMilka
@GrzegorzMilka 3 жыл бұрын
I'm glad to see ideas from cat. theory getting more widespread :) A well prepared presentation, thank you!
@maximkosheleff
@maximkosheleff 3 жыл бұрын
Seems most fun and prepared talk :)
@deathvall3y
@deathvall3y Жыл бұрын
Came back at it after a year with some haskell attempts. With haskell syntax , I was sliding off of monad with some level of understanding of map and applicative functor. To me , monoid and applicative functor in C++ looked reasonably good . Though verbose in C++ but still grasping the concepts seemed easier . Here I'm only taking in the concepts whereas in the case of haskell the problem is both the syntax and concepts are new . So definately it was helpful for me.
@cwhy
@cwhy 3 жыл бұрын
Such a good idea for talks like this!
@KennethBoneth
@KennethBoneth Жыл бұрын
This guy absolutely killed it
@tae-inkim2014
@tae-inkim2014 3 жыл бұрын
So valuable video. Thank you.
@hanneshauptmann
@hanneshauptmann 3 жыл бұрын
This is simply amazing. Love it!
@paxdriver
@paxdriver 7 ай бұрын
This is so amazing lol the peanut gallery is adorable!
@Eyalkamitchi1
@Eyalkamitchi1 3 жыл бұрын
This is soooo good! Love those kids
@skyeplus
@skyeplus 3 жыл бұрын
The parser from example is effectful. It should take string as an input, or better - const char*.
@MrGyulaBacsi
@MrGyulaBacsi Жыл бұрын
The getStrings(.) example at 20:05 did not work for me this way. I had to replace the 'auto' keywords to exact type declarations then it worked. Like "std::function" for f1. Is there a way to still use those 'auto' keywords anyway? It'd be nicer and more compact and flexible.
@francisgrizzlysmit4715
@francisgrizzlysmit4715 Жыл бұрын
this is like abstract algebra's I used to study these in pure mathematics fun
@Stu49583
@Stu49583 2 жыл бұрын
Very very good presenter!
@CppCon
@CppCon 2 жыл бұрын
Thank you very much for this comment.
@SimGunther
@SimGunther 3 жыл бұрын
Smart cookies in the audience :)
@mm1979dk
@mm1979dk 3 жыл бұрын
32:42 so how does one pass the list of digits to convert them into a number when the characters are not even stored anywhere?
@ornil
@ornil 3 жыл бұрын
I am not an expert, but I think you just pass them through functions. Kind of like append("a", append("b", append("c", ""))) - where is this stored? (Basically, on the stack as function arguments, if you get right down to it). In general, functional programming doesn't appear to store anything until you get the final results.
@colin398
@colin398 11 ай бұрын
At 19:20 when you talk about how std::function is a functor, i'm confused about the type of the first parameter. Shouldnt the type of the first parameter be a std::function with one parameter (a std::function) that returns another std::function, rather than just a std::function that accepts the return type of the second parameter?
@colin398
@colin398 11 ай бұрын
nevermind, I just realized that an element of a vector is analogous to a return type of a std::function
@xdman2956
@xdman2956 9 ай бұрын
So, P is fixed (think of it like literally 'int') and then: type function from P (int) to T is a functor with parameter T because if I have a function `a` (name like in example) of this type, and can provide function from T to U and get function from ... I think this is pointless now, anyone gotta se it for himself. This talk is quite nice to intuitively understand functors: kzbin.info/www/bejne/m2fXiH16atZrq9k (skip to 12:52 for Functors, also there are notations at 5:55, though it's just pseudo-haskell, and it doesn't matter much anyway to understand the concept - there are pictures!). It has a bit different style to this great video I am commenting on rn. More pictures and thinking about functional stuff in a slightly different way. It is nice to see things from a bit different point of view too, so I recommend it for people that would like to deepen their understanding. So, to say that type F is a functor with param T is to say that it has function map (or fmap) with the following signature (in haskell notation with cpp's template sprinkled in): (T -> U) -> (F -> F). For example whe treating vector as functor, provided a function from int to float (as parameter) we get (return) function "map" from vector to vector. In this video however, we see slight change in currying: we write map as a function with signature ((T -> U), F) -> F. This (using same example situation of vector, int and float) reads: given a function from int to float and a vector of int as parameters, return vector of float. Signature in C++ is F(std::function, F) - if the functor F is now std::function (P is, as mentioned, some fixed type), than this function has signature std::function(std::function, std::function) which is exactly that of the function presented (19:25). We don't consider more abstract map function that given a function T -> U returns a function (F -> F) but rather want to provide function T -> U and the vector right away to get the other vector immediately. What I think absolutely got me for a moment is this change from thinking (T -> U) -> (F T -> F U) (very haskellian and what I got out of the talk I mentioned) to thinking in terms of (T -> U, F T) -> F U - very confusing when F is also a function type and everything is mixed together.
@xdman2956
@xdman2956 9 ай бұрын
So, P is fixed (think of it like literally 'int') and then: type function from P (int) to T is a functor with parameter T because if I have a function `a` (name like in example) of this type, and can provide function from T to U and get function from ... I think this is getting pointless, everyone gotta see it for himself. This talk is quite nice to intuitively understand functors: kzbin.info/www/bejne/m2fXiH16atZrq9k (skip to 12:52 for Functors, also there are notations at 5:55, though it's all just pseudo-haskell, and it doesn't matter much anyway to understand the concept - there are pictures!). It has a bit different style to this great video I am commenting on rn. More pictures and thinking about functional stuff in a slightly different way. It is nice to see things from a bit different point of view too, so I recommend it for people that would like to deepen their understanding. There, the definition is: to say that type F is a functor with param T is to say that it has function map with the following signature (in haskell notation with cpp's template sprinkled in): (T -> U) -> (F -> F). For example whe treating vector as functor, provided a function from int to float (as parameter) we get (return) function "map" from vector to vector. In this video however, we see slight change in currying: we write map as a function with signature ((T -> U), F) -> F. This (using same example situation of vector, int and float) reads: given a function from int to float and a vector of int as parameters, return vector of float. Signature in C++ is F(std::function, F) - if for the functor F we substitute now std::function (P is, as mentioned, some fixed type), than this function has signature std::function(std::function, std::function) which is exactly that of the function presented (19:25). In summary, we don't consider more abstract map function that given a function T -> U returns a function (F -> F) that can later be used to map any vector, but rather provide both: the mapping function T -> U and the mapped vector right away to get the other resulting vector immediately. So this is, I think, what absolutely got me - this change from thinking (T -> U) -> (F T -> F U) (very haskellian and what I got out of the talk I mentioned) to thinking in terms of (T -> U, F T) -> F U - very confusing when F is also a function type, everything is mixed together, and I don't know which type is the parameter.
@MichaelFJ1969
@MichaelFJ1969 3 жыл бұрын
Those kids are adorable!
@jewulo
@jewulo 3 жыл бұрын
How do those kids understand all of this?
@arnebovarne7759
@arnebovarne7759 3 жыл бұрын
It's a mix of too simple and too complicated. Too easy and it's obvious. Too complicated and it feels messy and unclear.
@vicissitude1210
@vicissitude1210 3 жыл бұрын
I wonder if FP is promoted by those who are predominantly programmers by occupation or whether it's mathematicians being bored. Using Haskell is torturous and it seems like I'm fighting the language more often than addressing the programming issue at hand. Moreover, something like std::vector entertained in this talk is cache-unfriendly because Ts will be interspersed by the flags that indicate whether the std::optional contains a value. I fear that following FP principles incurs runtime costs, where instances are coupled with extraneous state for tab-keeping (more specifically, it's encouraged to keep tab-keeping local to each individual instance), which calls for extraneous state checks and branching.
@YourCRTube
@YourCRTube 2 жыл бұрын
FP in general does not map great to HW and this is, I believe, one of the reasons it is not the predominate paradigm. Still the value in it is undeniable and we should take all the good we can.
@bearwolffish
@bearwolffish 7 ай бұрын
Slow clap. Legit eli5
@TruthNerds
@TruthNerds 7 ай бұрын
Great talk! My token of appreciation is focusing on the one thing where you're wrong (EDIT: in part). 😉 Fat interfaces are bad. Please, do not write fat interfaces… fat interfaces are, by definition, interfaces with low cohesion, which is bad. Fat interface = god object (or rather "an object with a god complex"…) The solution is to a) segregate interfaces and b) use free functions (e.g. in C++) where possible. Then you - and you may laugh now - educate your users accordingly. Ok, what if you tried but your users can't or don't want to be educated? Then you can still use e.g. the Facade design pattern to separate the user interface from the implementation interfaces! In C++ e.g., you can similarly use the NVI (non-virtual interface) pattern where the (here: fat) public interface consists of non-virtual methods that use a restricted set of protected (or private) virtual methods. In short, there's no real reason to punish implementers by forcing a fat interface on them.
@mangos1346
@mangos1346 3 жыл бұрын
Functional programming in C++ looks really awkward
@ABaumstumpf
@ABaumstumpf 3 жыл бұрын
Functional programming in general is really awkward - it has its use in specific applications, but for general programs it is very verbose and hard to reason about.
@selayarlaut2746
@selayarlaut2746 2 жыл бұрын
@@ABaumstumpf in haskell, fp looks less intimidating, and you could make a generalization really simple. It just that Cpp define fp in a really verbose way, since it wasn't build specifically for fp
@MSK_MKT
@MSK_MKT 3 жыл бұрын
lol love the kids
Как быстро замутить ЭлектроСамокат
00:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 12 МЛН
100😭🎉 #thankyou
00:28
はじめしゃちょー(hajime)
Рет қаралды 56 МЛН
Indian sharing by Secret Vlog #shorts
00:13
Secret Vlog
Рет қаралды 59 МЛН
What the Heck Are Monads?!
21:08
ArjanCodes
Рет қаралды 67 М.
Back to Basics: Exceptions - Klaus Iglberger - CppCon 2020
1:01:45
Brian Beckman: Don't fear the Monad
1:07:10
jasonofthel33t
Рет қаралды 396 М.
OO Considered Harmful - Phil Nash - CppCon 2020
57:39
CppCon
Рет қаралды 45 М.
What is a Monad? - Computerphile
21:50
Computerphile
Рет қаралды 591 М.
Dear Functional Bros
16:50
CodeAesthetic
Рет қаралды 450 М.
Pratik Cat6 kablo soyma
0:15
Elektrik-Elektronik
Рет қаралды 8 МЛН
Эффект Карбонаро и бумажный телефон
1:01
История одного вокалиста
Рет қаралды 2,7 МЛН
Mi primera placa con dios
0:12
Eyal mewing
Рет қаралды 516 М.