DEV Community

Anton
Anton

Posted on

Haskell for javascript programmers.

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

Top comments (7)

Collapse
 
bennypowers profile image
Benny Powers 🇮🇱🇨🇦 • Edited

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
Collapse
 
entrptaher profile image
Md Abu Taher

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.

Collapse
 
antonrich profile image
Anton

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.

Collapse
 
eljayadobe profile image
Eljay-Adobe

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.

Collapse
 
felipperegazio profile image
Felippe Regazio

omfg thats awesome, tks

Collapse
 
vigyanhoon profile image
Sanjay Pandey

Why wear headphones when recording?

Collapse
 
drewknab profile image
Drew Knab

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