Haskell for javascript programmers.
Anton

Anton @antonrich

About: Born into being.

Location:
Russia, Yoshkar-Ola
Joined:
Oct 5, 2017

Haskell for javascript programmers.

Publish Date: Sep 21 '18
53 7

This is such a wonderful video. I just gotta share it.

Comments 7 total

  • Md Abu Taher
    Md Abu TaherSep 21, 2018

    Even though he explained it really well, I see why it's not popular, because like too many limitations and we hooomans don't like to have any limit.

    He explained the limitations and their workarounds. Such FP is for PROs. :D

    Good video, thanks for sharing.

    • Anton
      AntonSep 21, 2018

      These limitations only seem to be limitations. I used to be afraid of Haskell. Until recently I went to edx.org and pulled out their old course on FP with Eric Meijer. It's actually not intimidating. In Haskell you don't have to explicitly write
      \x -> (y -> (z -> x + y + z)))
      you can just write
      \x y z -> x + y + z

      When I first saw the video I thought the same way. Then it dawned on me that the point was to just introduce PURE functional programming through JS. It is tedious and feels limiting to write PURE FP in JS but it's different in Haskell (or other FP languages), that's the point.

      • Eljay-Adobe
        Eljay-AdobeSep 22, 2018

        JS is not a good language for trying to do "pure FP". However, Elm is a language that is ML inspired, and transpiles to JS.

        Elm is undergoing a lot of change as it evolves. It's at 0.19, but still worthy of taking a serious look at it. Even for production, depending on one's production qualifications.

  • Felippe Regazio
    Felippe RegazioSep 21, 2018

    omfg thats awesome, tks

  • Sanjay Pandey
    Sanjay PandeySep 22, 2018

    Why wear headphones when recording?

    • Drew Knab
      Drew KnabSep 22, 2018

      So you can hear the volume and clarity of your voice through the microphone and can adjust your voice/proximity to the microphone.

  • Benny Powers 🇮🇱🇨🇦
    Benny Powers 🇮🇱🇨🇦Sep 30, 2018

    Cool stuff. Haskell is such a pleasure to use.

    A few notes:

    No arrays in functional JS? Why the heck not?

    const head = ([x, ...xs]) => x
    const tail = ([x, ...xs]) => xs
    
    head([1, 2, 3]) // 1
    tail([1, 2, 3]) // [2, 3]
    
    Enter fullscreen mode Exit fullscreen mode

    I've done plenty of functional js that used the array built-in. Since dynamism is one of JS's strengths, why throw it out?

    import { All, Any, mreduceMap, compose, propOr, not, isArray } from 'crocks'
    
    const includes = x => xs => isArray(xs) && xs.includes(x)
    
    const isAdmin = compose(includes('admin'), propOr([], 'roles'))
    
    const areAllAdmins = mreduceMap(All, isAdmin)
    const noneAreAdmins = not(mreduceMap(Any, isAdmin))
    
    areAllAdmins([
      {name: 'Anton', roles: ['author', 'admin']},
      {name: 'Ben', roles: ['author', 'founder', 'admin']},
    ]) // true
    
    noneAreAdmins([
      {name: 'Bill', roles: ['author']},
      {name: 'Ben', roles: ['author', 'founder', 'admin']},
    ]) // false
    
    Enter fullscreen mode Exit fullscreen mode
Add comment