Functional Design Patterns - Scott Wlaschin

Поділитися
Вставка
  • Опубліковано 24 вер 2017
  • In object-oriented development, we are all familiar with design patterns such as the Strategy pattern and Decorator pattern, and design principles such as SOLID.
    The functional programming community has design patterns and principles as well. This talk provides an overview of some common FP patterns, from the basics of partial application and currying all the way to monads and monoids.
    NDC Conferences
    ndcsydney.com
    ndcconferences.com
  • Наука та технологія

КОМЕНТАРІ • 225

  • @soumen_pradhan
    @soumen_pradhan 3 роки тому +133

    03:19 FP Design Patterns
    06:13 Core FP Principles
    06:50 Functions are things
    11:45 Types are sets
    20:50 Functions as Parameters
    29:30 *Every function is one parameter
    16:58 Exceptions in Functional Land
    40:47 Chaining functions instead of if-else
    43:07 Monad
    44:06 Bind mis-match functions
    49:40 Map (*Mappable types r functors)
    53:06 Monoids (Things with 3 rules)

  • @kylew121
    @kylew121 Рік тому +12

    1:04:55 - "A monad is just a monoid in the category of endofunctors"

  • @dansuh4914
    @dansuh4914 4 роки тому +171

    THE BEST talk that gracefully and beautifully introduces and explains monads. This should be how textbooks teach monads to programmers.

    • @rngesus8057
      @rngesus8057 2 роки тому +3

      yeah when i was 5 i picked up a NES controller and understood how mario jumped, didn't need a physics lesson on acceleration. when i picked up c# and learnt .SelectMany or .HasValue on nullable structs i learned about monads, didn't need a mathematics lesson on category theory.

  • @sjatkins
    @sjatkins 3 роки тому +63

    This is really excellent. As an out of practice math nerd who has made a living slinging code for decades this was a breath of fresh air. Despite the disclaimers of don't expect to understand everything on first listen it all made perfect sense. A fine job of teaching this stuff piece by piece.

  • @Arizard
    @Arizard 2 роки тому +12

    Scott is a brilliant teacher. It’s common for FP to be explained in a confusing way, but this talk is succinct and clearly explains the value of using a FP approach!

    • @lepidoptera9337
      @lepidoptera9337 2 роки тому +1

      What is the value of dragging your state over the stack a million times a second, exactly?

  • @Alex-xf8pl
    @Alex-xf8pl 4 роки тому +66

    one of the best programming talks i've seen

  • @faisalmemon8818
    @faisalmemon8818 2 роки тому +12

    A brilliant talk. It is plainspoken, direct, but conveys the real essence of the topic at hand. The slides are clear and fresh. Scott is a remarkable educator.

  • @Dominik-K
    @Dominik-K 2 роки тому +20

    I still love coming back to this talk, as it's one of the bests in succinctly explaining many very fundamental advantages of functional programming languages and the functional mindset itself

    • @tsp4axl
      @tsp4axl 2 роки тому +3

      My thoughts exactly. I’ve heard all the basic principles/benefits of FP before, like why purity is good, but this really gave me the realistic paradigm of how we should be thinking about solving our everyday problems with FP. Definitely need to revisit.

    • @lepidoptera9337
      @lepidoptera9337 2 роки тому +1

      @@tsp4axl I would suggest you think about the implications of putting multiple copies of your state variables on the stack for a little bit.

    • @digitalspecter
      @digitalspecter 2 роки тому +1

      @@lepidoptera9337 Why would you do that?

    • @lepidoptera9337
      @lepidoptera9337 2 роки тому +1

      @@digitalspecter I wouldn't, but if you take functional programming seriously, then that is exactly what happens. I mean, you can do a little better and just pass around a pointer to a structure on the heap, but that has its own problems. Either way, functional programming is horrible at handling state.

  • @vipulpatel-il9nb
    @vipulpatel-il9nb 5 років тому +86

    If more experts explained FP or any topic like this, we would all be programmers.

    • @monad_tcp
      @monad_tcp 5 років тому +28

      lol, implying imperative/oo people aren't programmers, I liked it

    • @dialecticalmonist3405
      @dialecticalmonist3405 2 роки тому

      @@monad_tcp
      Every programmer is a functional programmer.
      He's just showing how to use types to reduce syntax repetition and erros.

    • @monad_tcp
      @monad_tcp 2 роки тому +5

      @@dialecticalmonist3405 "Every programmer is a functional programmer". They do indeed "function" very well I guess.
      Sarcasm pass you by.

  • @EngineerNick
    @EngineerNick 2 роки тому +1

    This champion just casually drops the most intuitive explanation of the monad joke on the internet.

  • @korntewinboonchuay519
    @korntewinboonchuay519 2 роки тому +1

    Beauty of functional programming in plain english. This talk give me the light in my head of what really is the benefit of FP!

  • @ErnestLebedev
    @ErnestLebedev 3 роки тому +3

    The best functional programming introduction. Period!

  • @MarkusBurrer
    @MarkusBurrer 3 роки тому +3

    Best talk about functional programming ever. Thank you

  • @kahnfatman
    @kahnfatman 2 роки тому +1

    This is one of the many videos I found helpful and insightful which enlightens me on the way to FP. Thank you!!!

  • @dougmilford7814
    @dougmilford7814 3 роки тому +8

    Clear and understandable. You did an amazing job!

  • @fizzyeltsuo
    @fizzyeltsuo Рік тому +2

    A great speech that is still worth revisiting even after a long time.

  • @adrianbona
    @adrianbona 3 роки тому

    Four years later and this is still awesome

  • @fredgotpub871
    @fredgotpub871 Рік тому +2

    Excellent ! Best monad step by step explanation !

  • @MarquisBS
    @MarquisBS 2 роки тому +2

    Amazing objective unbiased talk!
    I am coming from an OOP perspective and I knew some of the FP principles already (and some of it is already influencing how I do certain things in OOP in certain contexts.
    Even though we only wizzed past some of the principles I think I never saw it clearer :)

  • @rrregis
    @rrregis 4 роки тому +11

    Outstanding clarity! Thank you!

  • @temoncher
    @temoncher 2 роки тому

    It's beautiful! I've looked at this for five hours now...

  • @Liimr114
    @Liimr114 3 роки тому +6

    This is a gem.

  • @aboutajedyneayoub921
    @aboutajedyneayoub921 4 роки тому +4

    Good talk and very good presentation. thank your for sharing your thoughts :)

  • @notsoren665
    @notsoren665 Рік тому +2

    A monad is a monoid in the category of endofunctors.

  • @edelrabe
    @edelrabe 2 роки тому

    Extremely digestible, thank you Scott

  • @nickscurvy8635
    @nickscurvy8635 3 роки тому +3

    "An OR object is not easy to make in object oriented"
    I knew my ventures into C++ would be useful.

  • @zhou7yuan
    @zhou7yuan 3 роки тому +23

    FP Design Patterns [3:10]
    OO pattern/principle [3:20]
    FP equivalent: Functions
    FP patterns are different
    Outline [4:16]
    (Some) Core Principles of Functional Programming [6:12]
    Core Principle: Functions are things [6:50]
    Core Principle: Composition everywhere [9:23]
    Designing with composition: Functions all the way down [10:22]
    Core Principle: Types are not classes [11:45]
    Types can be composed too [12:54]
    "AND" / "OR"
    "AND" types [13:46]
    Example: paris, tuples, records
    "OR" types [14:22]
    Real world example of type composition [15:05]
    Design principle: Strive for totality [16:57]
    Design principle: Use static types for domain modeling and documentation [20:13]
    Functions ad Parameters [20:50]
    Parameterize all the things [20:54]
    Tip: Function types are "interfaces" [25:10]
    Example: Strategy pattern [26:40]
    Example: Decorator pattern [27:30]
    1 parameter function [29:15]
    Pattern: Partial application [32:08]
    Pattern: Use partial application to do dependency injection [34:37]
    Pattern: Chaining callbacks with continuations [40:53]
    Monads [43:07]
    how to combining switches
    "Bind" is the answer! Bind all the thing! [44:30]
    Pattern: Use bind to chain tasks [46:30]
    a.k.a "promise" "future"
    Pattern: Use bind to chain error handlers [47:19]
    Maps [49:40]
    Guideline: Most wrapped generic types have a "map". Use It! [52:38]
    Guideline: If you create your own generic type, create a "map" for it.
    Terminology: Mappable types are "functors"
    Monoids[53:05]
    Pattern: Convert non-monoids to monoids [1:00:17]
    Pattern: Seeing monoids everywhere [1:02:22]
    Metrics guideline: Use counters rather than rates / make sure your metrics are monoids
    Monads vs. monoids [1:03:54]
    "monad laws" are just the monoid definitions

  • @jgkim3802
    @jgkim3802 3 місяці тому

    모나드를 간단하고 덤덤하게 설명 잘해 주시네요 . 감사합니다

  • @Djefflangus
    @Djefflangus 3 роки тому +8

    Excellent - once I got past the dinosaurs it really gave me a really excellent insight into this paradigm. I did computer science in 1982 and I really struggled with OOP and actually gave up eventually - focused instead on Machine programming and PLC's - just too different from the way I think.
    This on the other hand is exactly how I think. Its like Asperger programming! And I am one of those!

    • @etodemerzel2627
      @etodemerzel2627 3 роки тому +2

      In modern times, OOP is a weird thing. It's very popular. Yet it makes everyone's lives so much harder.

  • @KryvenkoVolodymyr
    @KryvenkoVolodymyr Рік тому

    amazing. best FP video I've ever seen

  • @TihomirKit
    @TihomirKit 3 роки тому +19

    "It's really simple and I will show you. Now this is getting complicated." XD

  • @tmosest
    @tmosest 2 роки тому

    Great talk on Functional programming!

  • @raymondyoo5461
    @raymondyoo5461 6 місяців тому

    Great talk 👍👍
    Gained a lot of in-depth insights only in an hour

  • @mandosGOD
    @mandosGOD 5 років тому +5

    Brilliant!

  • @444haluk
    @444haluk 3 роки тому

    This man is mad genius, my brain is just exploded, a couple of shopping-list-like lines of code can be compiled into the exact same thing. As if I am talking to the machine and it is talking back.

  • @tanmoymajumdar8096
    @tanmoymajumdar8096 3 роки тому +2

    this is simply awesome, thanks for the talk

  • @juang.garcia7390
    @juang.garcia7390 2 роки тому

    That was mind blowing!

  • @warwolt
    @warwolt 2 роки тому

    Incredible talk

  • @mateojovani
    @mateojovani 3 роки тому +3

    The one parameter function concept is a game changer

    • @telaferrum
      @telaferrum 2 роки тому +5

      If you're interested, the name of that concept is "currying", named after Haskell Curry, the same person the Haskell programming language is named after.

    • @mskiptr
      @mskiptr Рік тому

      Also, functions like
      add : (Int, Int) -> Int
      add (x, y) = x + y
      take only one parameter too*! They take pairs
      *depends on the language tho

  • @GeofreeOFree
    @GeofreeOFree 3 роки тому

    Great slides! Great graphics! Wonderfully subtle humour!

  • @MCLooyverse
    @MCLooyverse 2 роки тому +17

    I love that quote "A monad is a monoid in the category of endofunctors", because it's a great example of jargon, but also, it just boils down to (in the context of functional programming) `M` is a monad when you can write `pure : a -> M a` and `join : M (M a) -> M a` for it, so it's not really difficult to understand, you just have to hand-wave through a couple of Wikipedia pages :p

    • @bigstones84
      @bigstones84 Рік тому +1

      You must be one of those who understood and can't explain it anymore :p There's one of those "Hitler meme" videos on FP if you haven't seen it, it's hilarious

    • @MCLooyverse
      @MCLooyverse Рік тому +1

      @@bigstones84 I'll have to look that up.
      It depends on what you mean by "explain". I've always been one for actual definitions over partial intuition, so, for me, that quote, a few examples, and enough time with Wikipedia are enough.

    • @AlLiberali
      @AlLiberali 11 місяців тому

      Wut?

  • @Niohimself
    @Niohimself 2 роки тому

    I didn't understand functional programming before, but now I do.

  • @MarincaGheorghe
    @MarincaGheorghe 4 роки тому +1

    Great speaker.

  • @kitkarson4226
    @kitkarson4226 Рік тому

    Scott is the best teacher

  • @driziiD
    @driziiD 3 роки тому +1

    anti-tip: you can also 'superficially slim down' the pipe by chaining function calls within the function body

  • @anantmishra6783
    @anantmishra6783 Рік тому

    killed it! awesome!

  • @Miggleness
    @Miggleness 3 роки тому +140

    FP diehards be like, "its so simple let me show you. This is gonna get complicated so excuse me if it's confusing"

    • @arisweedler4703
      @arisweedler4703 Рік тому +2

      This was not his best talk explaining the concepts for sure. He really didn’t say much of anything IMO. He’s awesome, but this talk is just mid

    • @javierrodriguez4218
      @javierrodriguez4218 Рік тому +1

      Well, it was more complicated that adding 1 + 2, but not that much.

  • @driziiD
    @driziiD 3 роки тому

    the doX functions in 43:01 have a type signature of: Option.Val -> Option

  • @mikolajsemeniuk8574
    @mikolajsemeniuk8574 Рік тому

    Great video

  • @SpiritVector
    @SpiritVector 2 роки тому

    you can have a very limited set of functions but yet achieve an entire set of elements even from input to output (input == output) by looking at these elements as a set that can make up a group given the right function a.k.a operation.

  • @DInfinity3
    @DInfinity3 5 років тому +1

    The best!

  • @driziiD
    @driziiD 4 роки тому +18

    oh okay, a monoid is anything i can do a "reduce" on

    • @Alche_mist
      @Alche_mist 3 роки тому +5

      This is the explanation I needed.

  • @aoeu256
    @aoeu256 3 роки тому

    Very well explained!

  • @PaulSebastianM
    @PaulSebastianM 4 місяці тому

    I need to share this with the team.

  • @phatrickmoore
    @phatrickmoore 3 роки тому +2

    I am getting ready to start watching the video so peeped the comments. Sounds like this talk is going to change my life. Hitting play now!!

    • @phatrickmoore
      @phatrickmoore 3 роки тому

      Just going to skim the f# wikipedia a little before

  • @driziiD
    @driziiD 3 роки тому +4

    a functor is any type that provides a 'map' function!
    Options provide a 'map' function

    • @matheusjahnke8643
      @matheusjahnke8643 3 роки тому +5

      Yes, Option is a functor. (On Haskell, it's "data Maybe a = Just a | Nothing", so it can be "Nothing" or Just with a value "a" and its actually "fmap" on haskell because "map" is only for lists because... reasons)
      Instead of doing:
      maybePlus1 :: Maybe Int -> Maybe Int
      maybePlus1 Nothing = Nothing
      maybePlus1 (Just a) = Just (a+1)
      You can do:
      add1 :: Int -> Int
      add1 x = x+1
      maybePlus1 :: Maybe Int -> Maybe Int
      maybePlus1 mappableThing = fmap add1 mappableThing
      Or, if you are really mad, you can write:
      add1 = (+1)
      (+1) is a function that adds 1 to the input, not the number 1. If you have a infix operator, let's write %$% for it, we can write: (%$% x) as a function that receives "y" and returns "y %$% x". This is what we call section
      If you really thing, you can write:
      maybePlus1 mappableThing = fmap (+1) mappableThing
      Note that I omitted the type of the function - the compiler can infer it. And it will not be exactly the same result. It will note that (+1) can only work on numbers, and fmap will work on functors, so it infers maybePlus1 :: f num -> f num
      "num" can be any type that is numeric(there is a 'typeclass' for that) and "f" is any type that is a functor.
      And now, just one more thing: you can think "fmap" receives a function and a functor, then applies the function to the functor. That's a way to think. Another is that it receives a function "a -> b" and lifts it into another realm: "f a -> f b". With that, fmap (+1) is a function from functors to functors.
      maybePlus1 = fmap (+1)

  • @LonliLokli
    @LonliLokli 3 роки тому +2

    Audience is too quite, I believe that's why Scott referencing another video on his site ;)

  • @kamilzielinski504
    @kamilzielinski504 2 роки тому +1

    This one railway two tracks illustration says more than a whole medium article

  • @nitinsharma4593
    @nitinsharma4593 5 років тому

    Excellent !!

  • @merseyviking
    @merseyviking 2 роки тому +3

    So if golang had monads, would they be gonads? I'll get my coat.

  • @csbnikhil
    @csbnikhil 3 роки тому +1

    29:02 Didn't get how the same log function was taking an int (first) and a bool (second).

    • @0LoneTech
      @0LoneTech 3 роки тому +4

      It probably doesn't take "int" or "bool", but "some type such that there is a known show function for it". This is known as a type class. For C++/Java people, it's a bit like an interface and a template function. So a type such as "Show a" guarantees there exists a "show :: a -> String", and thus log can call it to get something to work with. (This example uses Haskell syntax, but I expect it's similar in F#. I imagine this "log" is like Haskell "traceShowId".)

    • @csbnikhil
      @csbnikhil 3 роки тому +1

      @@0LoneTech Got it. The type is parameterized, return type is the same as the input type. Makes sense. Thank you!

  • @maertscisum7243
    @maertscisum7243 9 місяців тому

    How to do this in typescript? Recommendations?

  • @GT-tj1qg
    @GT-tj1qg 2 роки тому +4

    Arguably, the distinction between types and classes is purely aesthetic.
    After all, the word class in its conventional sense (from which the OOP sense is derived) refers to "a set of things" which is the same as your definition for a type.
    Likewise, you say that types have no behaviours, but you could think of any function that takes an input of that type as being a behaviour of that type.
    But, perhaps that's okay. Aesthetic differences can be worth making sometimes.

    • @warwolt
      @warwolt 2 роки тому +1

      An important thing about methods though is that they're part of defining the type, so a class is just a particular way of forming types, types are more general (e.g. structs and variants)

    • @johncip
      @johncip Рік тому +3

      It's far from being an aesthetic difference. Classes define the behavior of objects. Types are for type checking. They're orthogonal concepts -- you can have type-checked values which are not class-based, and many OO languages don't do type-checking before runtime.
      What's throwing you is that in Java and other places, the class names also get used as the types.
      > class in its conventional sense (from which the OOP sense is derived) refers to "a set of things"
      What's relevant is the technical sense in which OO languages use the word. Classes categorize behavior, and enable delegation; types are for memory allocation and compile-time safety checks.
      > any function that takes an input of that type as being a behaviour of that type
      I **think** you're saying that we can pretend that every value of type X, in a given language, is a member of a "class" where every function that takes an X is a method on that class, and the passed-in value acts as the class instance. But the analogy breaks as soon as you consider functions of more than one argument.
      Functions are the more general concept. It'd be more useful to relate these things by viewing instance methods as functions that take a hidden first argument, because that's more or less what they are, under the hood (but dynamic dispatch complicates things).

  • @edgeeffect
    @edgeeffect Рік тому

    Where in the ivory tower do the JavaScript developers live? ☺

  • @centerfield6339
    @centerfield6339 2 роки тому

    I need to heckle the TwelveDividedBy function bit to say that most integers given won't return an integer.

  • @wolfgangfrech5942
    @wolfgangfrech5942 4 роки тому +1

    Most tangible metaphor for bind I have ever seen.

  • @PandaTheGFX
    @PandaTheGFX 3 роки тому +1

    9:05 - This guy nodes

  • @posteisnoob5763
    @posteisnoob5763 Рік тому

    amazin

  • @tricky778
    @tricky778 5 років тому

    I accept a nonzero int that can divide 12 without using any storage and can always be done *before* anyone pulls the power cord - or else can keep working even without power and through the heat-death of the universe... ... ... uhh, I'll throw an exception

    • @okdoomer620
      @okdoomer620 5 років тому +1

      You probably shouldn't make the caller responsible for how they call the function, and instead return an Option of Int. If you're being consequent with this stuff, and all your functions are well defined for the entirety of the input set, you just eliminate places where stuff goes wrong. If your functions are simply not able to return Exceptions, then you never get an exception. You need language support for this though, in most OO languages this is impractical.

    • @monad_tcp
      @monad_tcp 5 років тому

      but if someone pulled the power cord, the caller won't be running to see the result too, the computation would be halted anyway, so the fact doesn't matter at all

    • @tricky778
      @tricky778 5 років тому

      @@monad_tcp exactly, pulling the power cord is just like an exception, its caught by the universe so the universe doesn't have to halt. Every function is a declaration, the computation happens in some Monad and the reality monad includes the power-off exception *but* it also includes excess power draw triggering power off so the definition of the function is always relevant, and intentional equivalence can be found by computing the result and that equivalence is a parameterisation of the reality monad. My conclusion is that every function must be lifted to some function reader and cannot be pure unless it is. I think the reader could be a polymorphic parameter. This is very similar to category theory and could be a useful direction.

  • @yevgeniygorbachev5152
    @yevgeniygorbachev5152 2 роки тому

    15:00 So unions from C, then?

  • @halfsourlizard9319
    @halfsourlizard9319 7 місяців тому

    Oof, I am fond of OCaml and F#, but the choice to write the type of `Some 5` as `int option` is really rather unfortunate. Haskell's `Maybe Int` seems much more consistent/readable.

  • @MrWorshipMe
    @MrWorshipMe 3 роки тому

    Aren't "Or" types just enums? Why is it so difficult to have those in c#?

    • @kalvino3515
      @kalvino3515 3 роки тому +3

      Not enums, unions (C/C++)

    • @Geert2682
      @Geert2682 3 роки тому +1

      Note that in F# the 'OR'ed fields don't necessarily occupy the same memory in the way that a C/C++ union fields do. So in C# you can just get the same behaviour by having a class/struct with an enum discriminator field. It's just that the C# syntax will be hella clunky.

    • @kalvino3515
      @kalvino3515 3 роки тому +1

      @@Geert2682 Oh, didn't realize that, either way, OO languages are def not designed around Functional principles, and vice versa

    • @berylliosis5250
      @berylliosis5250 3 роки тому +1

      @@kalvino3515 Tagged unions, more specifically. Accessing using the correct variant is enforced at compile time, don't need to do it explicitly. Sum types are only a little more workable in C/C++ than in C#

  • @Tyler-xc2ib
    @Tyler-xc2ib 3 роки тому +2

    In some cases, I believe it will cause stack-overflow when it calls functions too deeply...

    • @telaferrum
      @telaferrum 2 роки тому +3

      It only really happens when you're using recursion, and it's not so much an issue in functional languages since they tend to include tail call optimization, removing the previous call from the stack when you call the next function.

  • @jordanh9520
    @jordanh9520 3 роки тому

    Watching this as a C, JavaScript, and PHP holdout... Thinking WTH is an option?

  • @SuperQuwertz
    @SuperQuwertz Рік тому +1

    Where is the FIzzBuzz example again?

  • @caddr
    @caddr Рік тому

    great talk, now i can understand the meme

  • @xoxoshaneandmexoxo
    @xoxoshaneandmexoxo 4 місяці тому

    Is this about interior design

  • @willtheoct
    @willtheoct 2 роки тому

    this should be taught in every computer science class so we dont end up with tragedies like stackoverflow and c++

  • @bboysil
    @bboysil 3 роки тому +1

    For me, the phrase "function composition is a monoid" makes no sense to me....
    What would make sense would be something like "the set of all endomorphisms under function composition form a monoid" or "the functions from a set into the same set form a monoid with respect to function composition". Is this what the author meant? If so.. I would argue then that his wording is incorrect. If this is not what he meant, can someone shed some light? Thanks

    • @bboysil
      @bboysil 3 роки тому +1

      @@metaturso well, a monoid is an algebtaic structure that contains multiple elements, one of wich is the operation... i this case it is function composition. So it is not correct to say that function composition is a monoid... It's like saying addition is a group when actually the integers together with addition form a group...
      I hope I make sense

    • @bboysil
      @bboysil 3 роки тому

      @@metaturso Neither do I, and that is why I'm asking. Just trying co reconcile what he says with my mental model or with what I inderstood so far.. Whenever there's a mismatch, I have to ask because eother I didn't understand or he made a mistake. In either case, it gives me more confidence in my understaning and I can move further at greater speed. Anyway, thanks for the reply. I wish you a grandious week :D

  • @shadeblackwolf1508
    @shadeblackwolf1508 2 роки тому

    The infinite series mathmaticians want a word with you on that order of additions doesn't matter point.

  • @santaespinal1540
    @santaespinal1540 6 місяців тому

    🎯 Key Takeaways for quick navigation:
    00:24 🎙️ Functional design patterns and principles are demonstrated using F# but are applicable to various programming languages.
    01:36 🤖 Scott Wlaschin, the presenter, introduces himself as an object-oriented programmer turned functional programmer with a background in Smalltalk and other languages.
    03:15 🛠️ The talk will cover core principles of functional programming, including functions as parameters, composition, and the role of types.
    06:31 🧩 Core principles of functional programming include treating functions as standalone entities, using composition extensively, and distinguishing types from classes.
    08:48 🔄 Functions can be used as inputs and outputs, leading to powerful and flexible composability in functional programming.
    11:55 🧑‍🔬 Types in functional programming act as sets of data, allowing for flexible composition using "and" and "or" operations.
    16:51 🏗️ Functional programming excels in domain modeling, where types can be composed using "and" and "or" to create powerful and expressive structures.
    17:07 🚧 Designing for totality involves ensuring functions are total (never throw errors) by either constraining inputs or using types like "Maybe" to handle potentially undefined outputs.
    20:09 📚 Using static types for domain modeling provides clear documentation, compile-time checks, and helps design total functions.
    21:58 🔄 Parameterizing functions, including the looping action and list type, enhances flexibility and decouples behavior, a key principle in functional programming.
    22:13 🔄 Generic List Iteration in F#: F# makes list iteration easy, allowing for generic list iteration with parameters like action and initial value.
    23:11 🔄 Common Code Extraction in F#: In F#, the fold function helps eliminate duplicate code by extracting common elements, parameterizing the initial value and action, emphasizing the importance of functional collection functions.
    25:34 📦 Functions as Interfaces in F#: In functional programming, functions serve as interfaces, aligning with principles like the Single Responsibility Principle and Interface Segregation Principle. Functions compatible with an interface don't require inheritance.
    26:42 🔄 Functional Approach to Strategy Pattern: In functional languages, the Strategy pattern is implemented by passing the strategy (function) as a parameter, avoiding the need for class interfaces.
    27:52 🔄 Decorator Pattern in Functional Style: Rather than classic decoration with wrappers, functional languages use composition, combining functions to create new ones. The example showcases logging without explicit wrappers.
    29:24 🔄 Single Input, Single Output Principle: While multi-parameter functions exist, every function in functional programming can be conceptualized as a series of one-parameter functions, offering simplicity and consistency.
    32:11 🔄 Partial Application and Flexibility: Partial application allows flexibility by transforming a multi-parameter function into a series of one-parameter functions, demonstrating its usefulness in various scenarios.
    34:52 🧩 Dependency Injection with Partial Application: Dependency injection in functional programming can be achieved using partial application, providing flexibility without relying on specialized frameworks.
    38:27 🔄 Parameterizing Behavior: By parameterizing behavior, functions gain flexibility, enabling the caller to decide the next steps, illustrating the power of parameterization in controlling program flow.
    41:13 🔄 Monad Simplified: The concept of a monad, often viewed as complex, can be simplified as chaining continuations together. The example demonstrates this with a helper function for handling optional values.
    43:20 🚂 Gluing functions together involves using a branching railway analogy, where functions can either return something or nothing.
    44:29 🔄 Switch functions with one input and two outputs pose a challenge in composition. The solution is to use "bind," a functional programming concept that transforms one kind of function into another.
    45:52 🔄 Bind is the core of a monad, simplifying the gluing of functions and transforming one function type into another.
    46:20 🌐 Using the example of handling errors in a web service, the talk introduces the concept of monads to simplify code, making it look similar before and after error handling.
    48:59 🔄 The talk discusses how the mapping pattern, using functions like "map" on different types, is a common and powerful approach in functional programming.
    52:58 🔤 Functors, or mapable types, are discussed, emphasizing the importance of the "map" function in functional programming.
    56:41 ➕ The talk delves into the concept of monoids, which are sets equipped with a binary operation, associativity, and an identity element, providing a generalized structure for combining elements.
    01:02:52 🔄 Functions and function composition are explored as monoids, where combining functions of the same input-output type produces another function of the same kind.
    01:04:12 ⚖️ Monads are discussed as monoids in the category of endofunctors, connecting the concepts of monoids and monads in functional programming.
    Made with HARPA AI

  • @johanponin1360
    @johanponin1360 3 роки тому +1

    he broke the burrito curse

  • @edgeeffect
    @edgeeffect 2 роки тому

    Golang needs it's own "special" implementation of monads.... so, as well as 'goroutines', it could have...........

    • @edgeeffect
      @edgeeffect Рік тому

      (shrugs)... I thought it was funny.:(

  • @swstein
    @swstein 6 років тому +13

    Does some guy next to camera start eating crisps around 45 mins in?

    • @stephenkamenar
      @stephenkamenar 6 років тому +4

      it sounds like the camera itself is eating chips.
      maybe to recharge the battery since the speaker went overtime

    • @lizenz5046
      @lizenz5046 5 років тому

      It sounds like his shoes or maybe he is wearing leather trousers

    • @user-cb4pv5ip5i
      @user-cb4pv5ip5i 3 роки тому +3

      this is the sound of microphone being scratched by his beard

    • @yoyoclockEbay
      @yoyoclockEbay 2 роки тому

      Yes, pringles

  • @sinom
    @sinom 2 роки тому

    So TIL. Typescript is basically a functional language.

  • @TJ-hs1qm
    @TJ-hs1qm 2 роки тому

    Category Theory is to Programming what music theory is to Music.

  • @driziiD
    @driziiD 3 роки тому +2

    monadic bind =
    - takes in an Option & a Function
    - unboxes the Value out of the Option
    - passes the unboxed Value to the Function
    the functions passed to the monadic bind =
    - takes in a Value
    - returns an Option

    • @berylliosis5250
      @berylliosis5250 3 роки тому +1

      Yep, but you can use any monad - with a list, for example, bind is equivalent to flat_map:
      - takes in a list and a function
      - unboxes each value out of the list
      - passes each unboxed value to the function and combines each list
      function passed to flat_map/bind:
      - takes in a value
      - returns a list

    • @driziiD
      @driziiD 2 роки тому

      @@berylliosis5250 thanks so much! this is very true!
      (I realized this after looking into this stuff some more lol :))

  • @GT-tj1qg
    @GT-tj1qg 2 роки тому

    Railways are a strange analogy to use here because you can't send railway track down a train tunnel unless it's smaller

  • @MisterComment25
    @MisterComment25 3 роки тому +1

    Not me getting jealous some people get all these dope tools from their language while I have to use python at work...

    • @tatianabasileus
      @tatianabasileus 3 роки тому +5

      Python supports all of this (maybe except an option type) natively! Partial application is not inbuilt but there's the partial function in the functools builtin - that builtin has a ton of cool stuff you can use to program in a very functional way!

    • @Kuemmel234
      @Kuemmel234 2 роки тому

      ​@@tatianabasileus I think python is one of the worse languages to do FP in for work. Simply because for day-to-day stuff you don't have the chainable functions. There are of course filter and map on iterators, but I find list comprehensions much more practical (and they too have too much syntax, and you can't chain them) (in c-likes you can usually get the function as part of the returned object, you have the F# bar, or a threading macro - something to make lifting/binding short and easy to read). On top of that I really despise writing out lambda - sure, you can write a def for it (and that's actually a good thing in many cases), but still. Python is very verbose and annoying to read for FP. Even java does a better job for your lightweight FP stuff, like working with collections, option monads.
      FP is still a hard sell in many companies, so writing your own monads for collections is off the table (or even using some FP library). Or do you know something I don't for python in particular?

  • @driziiD
    @driziiD 3 роки тому

    bind == ifSomeDo

  • @johncip
    @johncip Рік тому

    This is a pretty nice talk but be warned that a lot of what it covers are things that aren't related to FP (e.g. discriminated unions). Many functional languages don't do static type-checking at all.
    If you're interested in the ML family of languages specifically, this covers a lot of their conventions. It mostly doesn't translate to e.g. the Lisp family though.

  • @artursvancans9702
    @artursvancans9702 2 роки тому

    So funny how he was afraid of using word "object“. Functions are things :D

  • @raianmr2843
    @raianmr2843 Рік тому

    this guy memes harder than most kids of my age

  • @halfsourlizard9319
    @halfsourlizard9319 7 місяців тому

    It's truly unfortunate how OO has presumptuously taken itself to be the 'default' frame of reference ... It bewilders me, coming from a functional background, why anyone would want their functions 'trapped' in objects and classes ... or how anyone finds it acceptable to have idiosyncratic/non-compositional abstractions.

  • @driziiD
    @driziiD 4 роки тому

    so monoids are value objects?

    • @skepticmoderate5790
      @skepticmoderate5790 4 роки тому +2

      A monoid is a binary operation whose inputs and outputs are of the same type, and which has an identity value. So, addition, multiplication, string concatenation, etc.

  • @justgivemeanumber8215
    @justgivemeanumber8215 3 роки тому

    what the hell is an endofunctor?!

    • @telaferrum
      @telaferrum 2 роки тому +3

      A functor that maps from one type (technically category) back to the same type.

  • @soulspirit86
    @soulspirit86 4 роки тому +2

    take a shot every time he says functions

    • @vnshngpnt
      @vnshngpnt 3 роки тому

      Man what have you done, I'm wasted now

    • @stolensentience
      @stolensentience 3 роки тому +1

      I wouldn’t be able to function

  • @SuperKako17
    @SuperKako17 2 роки тому +1

    "50% of your code is error handling..." Hahahaha. HAHAHAHAHAA. I wish, but people are usually more optimistic than that....

  • @AlLiberali
    @AlLiberali 11 місяців тому

    I like some of these ideas but I'd like to use them _inside_ my OO code with a language people would actually understand

  • @marloelefant7500
    @marloelefant7500 2 роки тому

    Visual Basic isn't a functional language, is that part of the joke? It doesn't quite fit into the image, I think.