No video

Nordic.js 2016 • Mattias Petter Johansson - If you know map, I will teach you monads

  Рет қаралды 22,107

Nordic.js

Nordic.js

Күн бұрын

Mattias Petter Johansson gave this talk at Nordic.js 2016. Read more at nordicjs.com/.

Пікірлер: 34
@donm4320
@donm4320 8 жыл бұрын
Your banana example made me think of this quotation: ❝Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad.❞ -Miles Kington Excellent talk.
@aben8763
@aben8763 4 жыл бұрын
Very nice! I think just by intuition here, that one does not imply the other. Practically, someone could be wise about something without fully understanding and vise versa.
@MrPDTaylor
@MrPDTaylor 5 жыл бұрын
OMG it's MPJ from fun fun function before he was KZfaq famous!!
@achillesnakmuay
@achillesnakmuay 8 жыл бұрын
I backed out of this conference last minute while 2 other co-workers went, if I had known MPJ was speaking I would not have cancelled my trip. God damnit!
@tehapo
@tehapo 8 жыл бұрын
Whew, at 9:17 you _almost_ spilled that water on top of your MacBook. 💦 But despite fearing for your laptop, I really enjoyed the talk. 👍
@funfunfunction
@funfunfunction 8 жыл бұрын
Funny enough, I have this policy that I should be able to drop my computer in a lake and continue working right away after walking into the nearest store and buying a new Macbook. If I had done that, I could have lent someones laptop and logged right into slides.com and continued. :)
@ChristopherOkhravi
@ChristopherOkhravi 7 жыл бұрын
Haha. Excellent policy! Thank you for the inspiration.
@JamesMarks
@JamesMarks 7 жыл бұрын
funfunfunction you're my new hero
@tauruscolvin
@tauruscolvin 4 жыл бұрын
Love you MPJ! Just a slight correction -- Promises and Monads differ in important ways. I've been noodling on Monads in JS for a bit and found a Promise-alternative called "Fluture": github.com/fluture-js/Fluture/wiki/Comparison-to-Promises#practical-differences Fluture provides a "Future" monadic structure which can (should?) be used instead of Promise. Practical differences: 1) Promises conflate `map` and `flatMap` into `then` whereas they should be distinct. In a true monadic structure (like a `Future`), `flatMap` would allow "chaining" into a different monadic structure (such as an `Either` aka `Result` or a `Maybe` aka `Option`). `Promise.resolve('hello').then(...)` always returns the same Promise container. 2) Promises are eagerly evaluated and are not cancellable. Futures are lazy and must be invoked by a caller which is responsible for handling success / failure. 3) Promises violate functor laws of composition. Now, I know that sounds a bit "foo foo" but it's important. Those laws are the "magic" which ensures algebraic data structures behave predictably for downstream users.
@thehappyperson4125
@thehappyperson4125 5 жыл бұрын
AHAHA .. for a second he thought he was on his channel.. look at 25:01 he smiled and was about to laugh controlled it somehow..
@centril
@centril 7 жыл бұрын
There are no functors or monads in JS because the language is dynamically typed and hence you can not restrict what types a mapper function f :: X -> Y, i.e: it could return varying types. In addition, even if f :: X -> Y, the function f must be pure, otherwise there's the possibility of the functor law: F(g o f) = F(g) o F(f) being violated. For example, if f is a function that prints to the console, and g does as well, then the order of side effects will not be preserved.
@collinrea6183
@collinrea6183 6 жыл бұрын
In a strict sense that is true, but it doesn't mean you cannot make a monadic acting function, you just wouldn't have the guarantees by the type system to know if anything in the program is acting as intended.
@adammoefoe
@adammoefoe 6 жыл бұрын
Mazdak Farrokhzad I know this isa very old comment, but when implementing monad in js you could check 'value instanceof Monad' (assuming the implemented 'types' using classes you used are extended from a base Monad class) . Major problems I see with this is performance when you don't need the result, i.e. >>. and with asynchronous functions. However, this run time type checking is not ideal and I think it's better to just discipline yourself to follow the monoidal rules. You won't have strong static types but you'll still be able to use the design patterns offered by monads
@generalflowdeveloper
@generalflowdeveloper 6 жыл бұрын
As I was following this talk, I kept thinking of the things that are doing the work as "functors." Those things -- map and mapTree -- are doing all the work. They are joining the dumb functions like capitalize, and the dumb data structures, into data structures with applied functions. Seems like they need a name. Higher order functions?
@KDOERAK
@KDOERAK 6 жыл бұрын
A great talk, thx!
@cevxj
@cevxj 7 жыл бұрын
Thanks for demystifying then!
@dtipson
@dtipson 8 жыл бұрын
If something as wacky as a Promise is legitimately a Functor and Monad (even though it doesn't have explicit .map or .flatMap interfaces), then Array and Tree are as well, no? In that you can add .flatMap to Array if you want, and also to Tree, if you want. That JS doesn't do this out of the box doesn't restrict what these types are capable of in theory (and in prototype modifying practice!).
@AtomicCruz
@AtomicCruz 7 жыл бұрын
Bluebird promises do have map and flatMap.
@piq-dg3vz
@piq-dg3vz 7 жыл бұрын
Drew Tipson they dont have to be called map or flatMap. They can be called then
@dtipson
@dtipson 7 жыл бұрын
Right: what the methods are called doesn't restrict what they are, though it does limit their interoperability with other types if everything calls .map something different. .then for Promises is not a lawful Monad interface, since it inspects the result and behaves differently depending on whether it's a .thenable or not.
@funfunfunction
@funfunfunction 7 жыл бұрын
Yes, Array would be monads in they implemented flatMap-
@piq-dg3vz
@piq-dg3vz 7 жыл бұрын
well.. the Javascript Promises has a botched implementation.. lol.. if it was implemented like Task/Futures then you would have a monad that directly follows the laws. github.com/fluture-js/Fluture/wiki/Comparison-to-Promises
@statequest
@statequest 7 жыл бұрын
Streams: kzfaq.info/get/bejne/aNCga7FnrcebpI0.htmlm3s
@AtomicCruz
@AtomicCruz 7 жыл бұрын
Why are Bacon, RX or Highland "hispter libraries"??
@JonasKroneberg385
@JonasKroneberg385 7 жыл бұрын
everything is a hipster library
@nyahhbinghi
@nyahhbinghi 6 жыл бұрын
Is flatMap the same as reduce?
@josebarona271
@josebarona271 5 жыл бұрын
no, reduce is similar to fold
@filip3074
@filip3074 5 жыл бұрын
when you call mapTree - reverse the arguments or it won't work
@Insipidont
@Insipidont 8 жыл бұрын
But Bananas are, botanically speaking, a fruit.
@funfunfunction
@funfunfunction 8 жыл бұрын
Nope - en.wikipedia.org/wiki/Banana
@Insipidont
@Insipidont 8 жыл бұрын
Did you bother clicking on the "Berry" link? en.wikipedia.org/wiki/Berry_(botany) "In botanical terminology, a berry is a fleshy fruit without a stone produced from a single flower containing one ovary" Congratulations, you learned something today!
@LizardanNet
@LizardanNet 8 жыл бұрын
Great scientific research
@gongfei
@gongfei Жыл бұрын
totally ruined it, congrats!
@tsooooooo
@tsooooooo 2 жыл бұрын
interesting topic but had to stop watching because the attempts at humour were too jarring
What is a Monad? - The Last Monad Intro You'll Ever Need
15:48
走歪的工程師James
Рет қаралды 20 М.
Underwater Challenge 😱
00:37
Topper Guild
Рет қаралды 24 МЛН
小丑把天使丢游泳池里#short #angel #clown
00:15
Super Beauty team
Рет қаралды 46 МЛН
Get 10 Mega Boxes OR 60 Starr Drops!!
01:39
Brawl Stars
Рет қаралды 19 МЛН
Nordic.js 2016 • Jem Young - Embracing The Future
30:15
Nordic.js
Рет қаралды 1,5 М.
Monads and Gonads
49:47
Google TechTalks
Рет қаралды 146 М.
What the Heck Are Monads?!
21:08
ArjanCodes
Рет қаралды 71 М.
Nordic.js 2014 • Douglas Crockford - The Better Parts
33:52
Nordic.js
Рет қаралды 70 М.
Monad - FunFunFunction #21
11:25
Fun Fun Function
Рет қаралды 126 М.
Be Careful With Return Types In TypeScript
12:08
Theo - t3․gg
Рет қаралды 62 М.
Nordic.js 2017 • Guillermo Rauch - Next.js by Example
36:09
Nordic.js
Рет қаралды 12 М.
Monads in JavaScript: I Promise you’ll have a good time by Max Nordlund
42:12
Why monads don't make sense in JavaScript
8:33
Fredrik Christenson
Рет қаралды 1,2 М.