Haskell for JavaScript programmers

Поділитися
Вставка
  • Опубліковано 3 січ 2025

КОМЕНТАРІ • 204

  • @valcron-1000
    @valcron-1000 5 років тому +153

    I learned more about FP in this video that in an entire semester at college

  • @TravisWatson
    @TravisWatson 7 років тому +155

    This video was awesome! I code a lot of functional(ish) stuff in JS and am interested in Haskell. When you said "no arrays" you broke my brain. I kept watching and it feels like my eyes were just opened! It's so clear now why recursion is important! Thank you thank you thank you!!!

    • @johnnyphoney5669
      @johnnyphoney5669 7 років тому +14

      It's not really true about "no arrays", you could have it if your really need it (for performance-critical parts for instance), look at this package: hackage.haskell.org/package/array
      But how you work with this arrays differs from how you do it in imperative languages.

    • @johnnyphoney5669
      @johnnyphoney5669 7 років тому +4

      See also hackage.haskell.org/package/vector

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

      @@johnnyphoney5669 Was asking this as a standalone comment. Array/Vector is much more efficient if you do non-iterative stuff. In fact, lists are even discouraged in haskell for anything but iteration. Length, index, elem, everything that does more than `head` is discouraged. www.imn.htwk-leipzig.de/~waldmann/etc/untutorial/list-or-not-list/

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

      Also note there are a lot of purely functional datastructures and the following book is a good resource for them: www.cambridge.org/core/books/purely-functional-data-structures/0409255DA1B48FA731859AC72E34D494

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

      is that make any sense that we're rejecting arrays, but allowing hashmaps a.k.a objects? because hashmaps are more complicated in their implementation, and usually based on arrays under the hood. and if array are not allowed, does that mean that standard JS map/filter/reduce are not pure?

  • @eboubaker3722
    @eboubaker3722 3 роки тому +7

    imagine he hits F5 in the middle of the video.

  • @nitinchandurkar3303
    @nitinchandurkar3303 6 років тому +37

    Amazing. Never seen this style of presentation. Thanks. Learnt a lot about Haskell this way. Would like to see some more of these videos.

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

    This video made me understand Haskell more than any of the dussins of Haskell tutorials I've watched so far

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

    "Functional programming is about *composing* pure functions". Thank you! Many definitions of FP leave aside this essential component. We don't just compute with pure functions -- we combine code itself with some more code and into different contexts! Now *that* is reusability taken to its ultimate expression.

  • @Pitometsu
    @Pitometsu 7 років тому +70

    Nix-shell, Haskell, Emacs. Good, very good! You had chosen the right side.

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

      @Gabriel Klenner well I can think of one you might have missed, vim is not Emacs.

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

      Gabriel Klenner VS Code + HLS + HLINT, emacs is for sheeps

    • @cranknlesdesires
      @cranknlesdesires 4 роки тому +14

      @@obinator9065 man, microsoft marketing is taking a bazaar route these days.

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

      @いあ I'm so torn apart. Using vim for a couple or years now, but only "really" using it for a couple of months to program. I don't want this big emacs ship, also vims community is much bighger. But so many advantages when using emacs as an IDE...I don't know.

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

      @@bratezoran2102 I'm not a pro, so take all this with a truckload of salt -- but neovim remedies some of vim's disadvantages as a IDE (& some of its features are 'backported', so to speak, into regular Vim via plugins). The upcoming 0.5.0 introduces a native LSP client & syntax engine; & the RPC interface makes it easily extensible, as it makes it trivial to communicate with whatever else over tcp or unix sockets.

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

    This is so cool, you type insanely fast! One of the limitation I would have highlighted for the passage to Haskell is strong typing, indeed fizzbuzz in JS returns a list of strings and numbers while the Haskell version returns a list of strings only. JS is more similar to Scheme in this sense

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

      If you watch his streams you'll learn he doesn't. He probably just speeds it up.

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

      I don't really think strong typing is all that new of a concept to most programmers, so it's something glossed over compared to things like currying. And really given Haskell's generic patterns and typeclasses, the strong typing isn't really as big an issue as most would expect. And honestly while you can pass in a bunch of weird arguments of different types into a JS function, you probably shouldn't. It makes the code a lot harder to understand.

  • @rojebd
    @rojebd 8 місяців тому +1

    Tsoding even though this video is old, your other videos inspired me to try haskell since it seems so cool and I don't know magical and this video helped me a lot, I finally made my own function that I understand!

  • @sumantkanala
    @sumantkanala 6 років тому +24

    Alright, I'm gonna be a subscriber for life. You have so much knowledge in one video, it's too good to be missed. Recommended for any modern developer!

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

    I love how you basically construct lisp in js here. Got here interested in JS and running emacs basically as an os, implying some lisp comprehension... gonna learn me some haskell now

  • @guillaumequittet9418
    @guillaumequittet9418 4 роки тому +9

    I thought I knew functional programming. I was wrong. Since watching your videos I have been able to solve some problems with the functional code I made. Thank you !

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

    I learnt haskell because I wanted ro improve my recursional thinking. Now I’m in love with it. The best decision ever.

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

    this is pure gold

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

    I'm new to the functional world and you have helped me greatly understand what is going on. Thank you so much for this video.

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

    Awesome! only one suggestion to get rid of the "dirty" functions:
    const a2l = arr => [...arr].reverse().reduce((l, i) => pair(i)(l), null)
    const l2a = xs => (xs === null ? [ ] : [head(xs), ...l2a(tail(xs))])

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

    The fact that you can just hammer that in the keyboard from the top of your head is impressive.
    When I program is more like hm hm hm think think *type thing in* hm oh no *delete again* hm think hm oh yeah *types thing in*
    I think people can hear the sound of an old modem coming from my brain in the thinking phases

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

      Saaammeee

    • @pharoah327
      @pharoah327 10 днів тому

      The more you do this kind of stuff, the faster you naturally get. Any senior level dev can do this type of stuff from their head at a fast speed. It's like anything, the more you do it, the faster you become.

  • @mohammedsalman3397
    @mohammedsalman3397 6 років тому +8

    Great video, well explained. You should make more like this

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

    This has to be one of the coolest coding videos i´ve ever seen.

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

    This its increible bro!!! You are the best profesor of functional programming i see! A hug from Venezuela. Thanx

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

    I just decided to learn Haskell after seeing some of your videos, and after searching, this was the first thing I found

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

    Very succinct description of FP in JavaScript. I couldn’t help but thing of lisp with the FP list that you created

  • @btavia-q9n
    @btavia-q9n 5 років тому +2

    Wow, this is mind bending

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

    Thanks so very much. I've made FP a personal study since 2013. I've wanted to break into Haskell and have been thwarted more than once. This is a great Haskell intro imho.

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

    спасибо большое. Очень четко и ясно. хотелось бы больше таких примеров с чистыми функциями и сравнения JS c Haskell

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

    What a starting point. Pure genius.

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

    I loved the explanation and now I am more interested in knowing Haskell.

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

    This is so useful. Your explanation is so informative and insightful.

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

    Incredible. This helped me grok FP and haskell SO MUCH BETTER! Thank you!

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

    Every Javascript Programmer should learn this presentation by heart!!

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

    Even though I hate JS, this video is great. I learned so much about FP from your videos. I really hope you are doing well.

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

    This is the BEST FP video that I've ever seen. Thanks man.

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

    in the first argument it's actualy use a condition checker which is like if Statement. in recursion we must find a way to get out so if statement it's required i think.

  • @georgespanos4680
    @georgespanos4680 8 місяців тому

    You are great man, thank you for the content.

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

    I thought I was gonna hate the video but turns out it was great, keep it up!

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

    Thank you for teaching me just how bad functional programming can be. I'll never attempt to step away from OOP again.

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

    amazing demonstration of haskell skill

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

    genius, i'd never thought in this way

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

    THANK YOU VERY MUCH, VERY HELPFUL IN WHAT FUNCTIONAL LOOKS LIKE

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

    Amazing!!!!! I hadn't thought of it that way. you have a fan here brazil!

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

    That was a great video! absolutely loved it ❤️ you should have more subscribers.

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

    Really good and useful video! Thanks a lot!

  • @waynee95
    @waynee95 6 років тому +2

    Really liked that video!

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

    Amazing explanation. Maybe you should repeat it with porth (if you implement anonymous functions)...

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

    There a good starting point so that people not used to FP can approach it and connect it with something that they may be more familiar with. Noice!

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

    Name of the outro song?

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

    Mind blowing pedagogue !

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

    I knew what was going on and was lost simultaneously. Very strange

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

    Impressed!👌✨

  • @vyacheslavogai
    @vyacheslavogai 7 років тому +2

    Great video about pure functions! Similar to when you visit another country and meet new people and learn something new about theirs' culture :)

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

    This video is pure gold!

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

    I tried PureScript once but I could not for the life of me figure out how to write the type signatures of effects or really understand their syntax. The pure functional types make sense, but the others were very confusing.

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

    this is really amazing stuff, thanks for sharing! i've been wanting to try to apply some of the knowledge of fn programming to my js knowledge but didnt know where to start

  • @symmetry-e8
    @symmetry-e8 Рік тому

    This explanation is so damn good

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

    When you implemented array2list why did you reverse the list instead of just iterating from xs.length - 1 down to 0?

    • @DavidAguileraMoncusi
      @DavidAguileraMoncusi 4 роки тому +6

      They're equivalent solutions... so probably his was the first one that came to his mind

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

      @@DavidAguileraMoncusi One is more efficient than the other though.

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

      @@jacobscrackers98 efficiency is clearly not a high priority in these examples (although of course Haskell does gain efficiency through pure functional laziness).

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

      @@chromosundrift If it doesn't cost anything extra, one should go for the more efficient option imo

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

      @@jacobscrackers98 Efficiency in Javascript wasn't the point. Lots of stuff he's doing like function currying are horribly inefficient in JS, but the idea was to understand Haskell better. Keep in mind that in haskell the compiler optimizes a lot of these things for you. So a lot of inefficient practices in JS aren't inefficient in Haskell, because Haskell is designed for that style of solution in mind.

  • @coldbloodedtenacity
    @coldbloodedtenacity 2 місяці тому

    So beautiful.

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

    Mindblowing!

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

    Incredible video

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

    If you don't account the Array limitation, you don't need to re-implement map and arrays to list, list to array. I understand why you did that, but in practice the only thing you really need is ranges.

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

    Really slick, great video!

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

    I think as a disclaimer it should be made clear that types also have to be pure in functional languages. Having a function returning either an integer or string is not possible in Haskell without a unifying type.

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

    This video just made a 501 in my brain

  • @snoopy8870
    @snoopy8870 7 місяців тому +1

    i don't understand why would somebody write all that code instead of if else statements and for loops, what's the benefit of FP over OOP?

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

    That was beautiful

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

    masterful editing

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

    Id expect n to return true.. Learned new on the JS side as a plus. Learning never ends!

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

    I think,that separating on 2 parts it's not a good trick, because haskeller also should know how write good Side Effect code using monad and etc.
    And using Side Effects through the powerful mathematic conceptions - it's actually beauty of haskell.

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

      Oh that's what is the purpose of monads! I've seen the example of monad that does the logging, and after reading this my eyes have opened.

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

    Very carefully crafted and easy to follow presentation! thank's a lot!

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

    wow. amazing video, really!

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

    Люто лайкую. Топчик.

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

    Looks fancy, but how much Stack Overflows does occuring in functional languages?

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

    quality content comrade

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

    Fantastic!

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

    Why are ternary operators allowed but not other forms of conditionals? Are nested ternary operators allowed?

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

    I do love me some javaskriept, great video!

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

    This was really helpful! Thank you

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

    Ah, yes, how to blow up the stack by creating a range.
    Great video tho !

  • @MrBenjjj6
    @MrBenjjj6 6 років тому

    That was amazing, thank you.

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

    great video, thank you!

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

    I assume this "no arrays" rule is just to firmly disallow random access inside a list of data? For actual as functional as possible within JS code, just using arrays as if it is a list (map, filter, reduce, and only traversing it using recursion) will be much more performant while conceptually being the same as functional programming, right?

    • @Leonhart_93
      @Leonhart_93 8 місяців тому

      Recursion is not more performant that straightforward iteration, it's the opposite. Firstly there is a call stack limit and if you reach it then the program crashes. Secondly, instead of a single CPU instruction like in a single iteration, an iteration using recursion also involves creating the function object.

    • @SteinGauslaaStrindhaug
      @SteinGauslaaStrindhaug 8 місяців тому

      @@Leonhart_93 yeah i know... Unless the language optimises tail call recursion, or you use recursive functions that isn't optimisable, it's quite limited in depth.
      But I meant using arrays in JavaScript is significantly faster than a homemade linked list would be.
      But I'm pretty sure the functional built in functional methods like map, filter etc. on the array objects are just as fast or faster than a for loop is in most js implementatons.

    • @Leonhart_93
      @Leonhart_93 8 місяців тому

      @@SteinGauslaaStrindhaug I do not think they are faster than low level loops. There is no imaginable reason why they would be faster than doing i++.
      Their purpose is to simplify working with arrays and stuff, for faster dev implementation, and not for more efficient runtime.

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

    Beautiful

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

    Как раз изучаю функциональное программирование на js

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

    Amazing ❤

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

    Great way to explain

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

    comfy

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

    I love this video!

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

    what... you can concatenate expressions in js

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

    Seems like 5 is a direct fallout of 3.

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

    why should there be no if conditions for it to be functional

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

    that fisbuzz example using if statement. while you said we cannot using ifs ?

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

      It's probably a bit late, but the Haskell "if ... then ... else ..." works like a ternary. The thing that's not allowed is just if ... then ..., because then there is no return value when the check fails.

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

    I'd like to contribute subtitles in English; would you please enable video subtitle submissions?

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

    No Ifs - how is the ternary operator different than writing out an if / else?

    • @0LoneTech
      @0LoneTech 2 роки тому

      It's different in that it forces each branch to produce a value, so all the logic is in the context of an expression. Basically, it works around having to remember to always include an else and two returns. Writing one language within another will tend to have awkward translations.

  • @georgecernat6166
    @georgecernat6166 6 років тому

    Great video

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

    No loop is a bit crazy to understand. Does that mean any arr.forEach, arr.filter is also not allowed in the classical way? Or these function isn't referred as a loop ? I think this needs to be clarified.

    • @0LoneTech
      @0LoneTech 2 роки тому

      forEach indeed does not exist, because in pure functional code it could not do anything; it returns undefined. The closest equivalent in Haskell is forM_ which operates within a monad as a way to model side effects. filter, on the other hand, is one of three core higher order operations on collections: map, filter, and reduce. Each of these produce a result, using some number of calls to a worker function they've been passed (mapping, predicate or reduction). Such higher order functions (often based on folds) usually replace loops, but recursion is the core mechanism. The core reason is that looping relies on side effects (something must be changing for the loop to complete). Without side effects, programs are easier to reason about and we can do things like evaluate multiple portions simultaneously.

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

    Thank you for this video. I wonder though about the use of ternary operators... In a way, is it not like using a "if"?

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

      In functional programing else is mendatory, because expressions always have value. Ternary operator enforces this constraint in procedural language.

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

      if is a statement and returns no value, so it cant be used

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

    mind blown

  • @bhavyakukkar
    @bhavyakukkar 10 місяців тому

    javascript can do all this but what do they use it for? let [count, setCount] = useState(0)

    • @Leonhart_93
      @Leonhart_93 8 місяців тому

      Yeah well, good luck designing the modern extremely complex UIs with those strict pure functional rules. Especially the avoiding side effects part.

    • @bhavyakukkar
      @bhavyakukkar 8 місяців тому

      @@Leonhart_93 thanks

    • @bhavyakukkar
      @bhavyakukkar 8 місяців тому

      @@Leonhart_93 thanks

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

    Thank you so much because now i fan of fp

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

    Won’t Java stack explode with recursion?

  • @tomislavzoricic5656
    @tomislavzoricic5656 6 років тому

    Great video!