11 ms·
Professor Frisby's Mostly Adequate Guide to Functional Programming (2015)
- gcanti 8y agoFor my fellow italians, I wrote a free "Introduction to functional programming" PDF, check out https://github.com/gcanti/functional-programming https://github.com/gcanti/functional-programming
- picardo 8y agoIs there an English translation?
- vga805 8y agoDr. Booleans guide is excellent. Another nice intro to functional programming using JavaScript is Kyle Simpsons functional lite:https://github.com/getify/Functional-Light-JS/blob/master/README.md https://github.com/getify/Functional-Light-JS/blob/master/RE... Kyle wrote the You Don't Know JS series. This book is just as good.
- jwarren 8y agoGreat book. I'd also recommend his free video course on Egghead. It's rather quirky, which is something that I very much enjoyed: https://egghead.io/courses/professor-frisby-introduces-composable-functional-javascript https://egghead.io/courses/professor-frisby-introduces-compo...
- zupa-hu 8y agoahahah, this is incredibly entertaining :D (Skip to 0:30 in the first video, it's full of this kind of "context".)
- AlexCoventry 8y agoHe should make a Professor Frisby plush toy with a voice system which provides a functional API. How do you transform someone's voice like that?
- lolive 8y agoThe video course is indeed very good, if you took the time to read (and understand) the book.
- akuji1993 8y agoActually the course on Egghead is terrible. The voice that is used to comment on the video is very badly recorded and I have no idea why they chose that voice for a serious video for adults. Edit: Also fine to not have my opinion on this, but a lot of people shared my opinion, check the Egghead comment section. I would've loved to watch that video, with a more professional voice and walkthrough.
- jwarren 8y agoI completely understand that it could be more difficult for non-native speakers to understand. It's been sped up to match the cartoon style characters that he uses, and presumably for information density. I personally really enjoyed it, even if I did have to frequently pause the videos to recap something he had just said.
- akuji1993 8y agoSee, isn't it a negative point for you, that you have to stop and revert the video to an earlier point frequently because of this. As someone who has learned a lot through video guides (which are my favorite medium to learn, other than just reading the docs), I think that talking slowly through complex problems is the better way to go, even if that means, the video will be longer.
- jwarren 8y agoTbh not really, I often stop to investigate stuff anyway. I personally prefer to have it at my pace and under my control than listen through someone laboriously explain something I know in great detail. But this is the great thing about the internet - there's so much information on how to make more of it, you'll definitely be able to find videos which are more to your taste. I recently watched Andrew Van Slaars series on the Maybe type: https://egghead.io/courses/safer-javascript-with-the-maybe-type https://egghead.io/courses/safer-javascript-with-the-maybe-t... - that was much more traditional and slower paced, and still very good. Maybe give that a shot if you found the Frisby stuff too frenetic.
- 8y ago
- tomduncalf 8y agoGreat book for an intro to FP if you’re a JS developer. I have a talk about it a few years ago aimed at complete newcomers to FP: http://blog.tomduncalf.com/posts/functional-programming-fundamentals-talk/ http://blog.tomduncalf.com/posts/functional-programming-fund...
- csixty4 8y agoWhen I started looking into Functional Programming, Professor Frisby's book was instrumental in my learning the concepts and applying them to a language I already know & code in.
- dagurp 8y agoExcellent book. Although it says 2015 in the title it's still actively being worked on.
- mkirklions 8y agoI spent about 30 minutes reading, but I didnt understand why this has 140 points and is the top thread. Can anyone explain?
- brianberns 8y agoFunctional programming (FP) is an important paradigm with many practical benefits, such as preventing bugs, improving parallelization, etc. JavaScript is a language in which one can apply the FP paradigm, with some (considerable) effort. This book explains both the underlying FP paradigm and how to apply it in JS. Other languages (e.g. Haskell, Scala, F#) are designed for the FP paradigm and make it much easier to apply. But the paradigm itself is the same for all of them, as it arises from fundamental mathematical laws.
- mkirklions 8y agoThank you!
- lloyd-christmas 8y ago> with some (considerable) effort disclaimer: I haven't read the book and am not sure if this is mentioned anywhere. What helped me when thinking about functional design in javascript was realizing that all js functions actually only have one parameter, an array of arguments used by the caller: function add(x, y) { return x + y; } is effectively syntactic sugar for function add() { const x = arguments[0]; const y = arguments[1]; return x + y; } `add(1,2,3,4)` ignores 3 and 4 instead of being an error. While seemingly obvious that these two functions would have different definitions: `add1(1)(2)` and `add2(1,2)`, thinking about it in types helped me process it when thinking out how they are actually written: add1 :: [Number] -> [Number] -> Number add2 :: [Number, Number] -> Number
- brianberns 8y agoYes. This is the essence of currying.
- projectileboy 8y agoFogus wrote a whole book on functional programming in Javascript, which I recommend if you liked this.
- tuukkah 8y ago> We have all the features we need to mimic a language like Scala or Haskell with the help of a tiny library or two. Seems misleading at best, as you mimic only some parts of functional programming. For example, for-loops are not used but neither are recursion and tail calls mentioned. > [T]yped functional languages will, without a doubt, be the best place to code in the style presented by this book. JavaScript will be our means of learning a paradigm, where you apply it is up to you. Surprising how they teach the typed functional programming paradigm in a language which does not support you in it. Going from JavaScript to Haskell, wouldn't PureScript be a better stepping stone than this? Consider tail call elimination or all the support that type checking gives you to get the type nestings right, especially when you are a beginner and may have issues even with String being [Char] (unlike JavaScript) let alone Monads etc. (EDIT: In case you didn't check the contents of the book: Yes, this is a book that teaches Monads, type classes, pointfree style, Hindley-Milner(!) etc., not a form of FP that would be natural in JS.)
- brianberns 8y agoIt seems like a good book, but I think this is fair criticism. It skips some of the basic FP concepts that you mentioned, and is surprisingly heavy on more advanced topics (e.g. category theory, which I personally enjoy). Most of the book isn't really a beginner's guide. A more accurate title might be "JavaScript for Haskell Programmers".
- weatherlight 8y agoMost people are familiar with JS, not a lot of people have experience with Haskell or OCaml, or F# (Otherwise, they wouldn't really find any of this useful.) And to the point... how would one go about taking "Imperative Haskell" Code and making it more functional... you can't. Either you write Haskell functionally or whatever you wrote will refuse to compile. I love this book and the Egghead.io videos that followed. I love this guide and the egghead.io videos. That content made me curious about Haskell and Tacit Programming.
- blindwatchmaker 8y agoReally enjoyed this book. Once you get currying, and using curried functions to pipe/compose, everything clicks into place. I found the examples of using Nothing/Maybe monads for error handling pretty neat as well - is that a common pattern, because I don't remember native support for those types when I briefly dabbled in elixir. Also is his explanation of monads as 'functors that can flatten' a simplification for the purposes of teaching, or is that more or less what they are?
- yen223 8y agoHaskell-style types aren't a prerequisite for functional programming. Lisp and Elixir are dynamically-typed, which is why you don't see monads in those. That said, they do occasionally form useful abstractions.
- AnimalMuppet 8y agoCan you explain why you don't need monads if your language is dynamically typed? That's a new one to me.
- marcosdumay 8y agoI don't agree with that "not needed" explanation. But they are quite useless if the compiler can not deduce that both the values returned from the functions you are calling are monads, and what kind of binding should apply to them.
- dvlsg 8y agoI find them to be at least somewhat useful in a language like javascript. I imagine they are more useful in a typed language with proper inference, but I wouldn't say they're entirely useless in a dynamic language.
- AnimalMuppet 8y agoOK, for the slow of understanding: What I think you said is that, in an untyped language, a function will just return "something" (as far as the compiler is concerned). But in a typed language, the compiler knows that a monad was returned. So the point of the monad is to make the compiler do magic, not to make the runtime do magic. Is that accurate?
- ponitozhekoni 8y agoThanks.
- tw1010 8y agoThis is excellent. But man, I don't think I can ever go back to not feeling like there's a huge pedagogical gap between the local maxima the functional programming explanations engineers are typically exposed to, and the much higher (though probably still not a global maxima) point that pure mathematicians have been adapted into. I just wish we'd embrace the geometric (topological, differential geometrical) threads that a lot of these concepts (like lifts etc) are connected to, instead of being arbitrarily tied to a pedagogy textured by the sociological context that coding originated from (i.e. heavily influenced by logicians etc).
- uryga 8y agoWhat threads do you mean? (The only thing that comes to mind is HoTT stuff, but that's kind of over my head for now)
- AlexCoventry 8y agoWhat's an example of a coding problem which would benefit from all that abstraction?
- tw1010 8y agoWhile I sympathize with your sentiment – and share the mindset during my day job – I believe that this type of "what practical applications does this have"-thinking is making us short-sighted and preventing us from being able to move past our current local maxima, to cross the adaptive valley[1]. I'm not expecting the whole engineering field to start exploring the question of what pure mathematics (and not some watered down for-engineers version) can do to fundamentally transform the the way programmers think and talk about what it is they do. But the fact that there are almost zero people from the geometric side of pure mathematics (though again, there are plenty of logicians) working together with everyday programmers, that's what I wish I saw more of every time I see one of these explanations of functional programming that seem almost always to be pedagogically colored by logicians hands. [1] https://www.edge.org/response-detail/23879 https://www.edge.org/response-detail/23879
- 8y ago
- christophilus 8y agoGood read. He annotates his function with Hindley-Milner type signatures (specified in comments). I really prefer this to, say, jsdoc. Anyone know if there's a jsdoc-like tool that understands these comments? That'd be pretty swank.
- theoh 8y agoI'm not sure what "Hindley-Milner type signatures" means. Obviously it is intended to refer to Haskell-style type signatures. Hindley-Milner, though, usually refers to a system of type inference which is independent of syntax. As I understand it, the author is using Hindley-Milner as if was the name of a syntax, like Backus-Naur form. But this is something I've never heard, and I wonder if the credit for the Haskell type signature style belongs just as much to Rod Burstall or David Turner, in other words I'm inclined to believe that it is something conventional that evolved over years.
- RobertKerans 8y agoFlow is a bolt-on on type system, not quite OCaml (which it was built in) but it's pretty good.
- dakom 8y agoThe Fantasy Land spec and related libraries like Sanctuary and Fluture deserve a mention here, even if only as a next step after reading this guide. It helps bridge the gap between looking at all of this from the more math/Haskell perspective and how it's implemented in javascript, without sacrificing definitions (as much as possible).
- ericyang321 8y agoExcellent read for a beginner like me who wanted to learn functional programming with an already familiar language.
- 0xdeadbeefbabe 8y agoSince the FP crowd is here, why is loading a program into memory, writing a register, or calling a function not seen as a side effect, but writing to disk is seen as a side effect? Or have I got it wrong?
- xfer 8y agoLoading a program into memory is part of runtime(it happens before your program starts executing; so how is that useful to model that?); Why would calling a function be a side-effect? Not sure what exactly you mean by writing a register; if you directly mutate a location, it is considered side-effect. Otherwise any register rewrites that happen are just implementation details and if you have a different architecture than von-neumann than it could also be implemented without writing to a register.
- ItsMe000001 8y agoAs long as software is executed in the real world you have side effects, including "side effects" coming in from the outside, like bits flipped in RAM. Yes. So let's just be practical. We can have the equivalent of a middle ages theological discussion or one rooted in this world :-)
- AnimalMuppet 8y agoI'm not really part of the FP crowd, but I'll take a stab at it. Note well, however, that what I say here could well be wrong. On one level, there is no such thing as FP. All there is, is assembly-language (or binary) instructions being executed in a CPU that has access to some memory. (Almost) every instruction creates some kind of side effect (including changing the flags). But nobody wants to program at that level, so we build abstractions on top of it. All higher-level languages create an abstraction. Even C creates an abstract machine, even though it's very close to the hardware. If the abstraction doesn't leak, you can just think about the abstraction, and ignore what's going on at the level(s) below it. FP creates an abstraction that's at a higher level than many other abstractions. Within that abstraction, (almost) all you have are functions and values. Memory and registers are below that level. The changes to the call stack when you call a function are below that level. Those things are therefore not seen as side effects, because they are below the level of abstraction you're working at. But disk is not. Therefore writing to disk is seen as a side effect, and those other things are not.
- lainga 8y agoThis may be a character flaw, but I found this book's style of teaching by mocking random snippets found in the wild really, really entertaining.
- stuntkite 8y agoYou should see the videos he made for Egghead.io! Stop motion hedgehog! I know some people complained, but Egghead backed his unconventional teaching methods which is pretty cool. - https://egghead.io/instructors/brian-lonsdorf https://egghead.io/instructors/brian-lonsdorf - https://www.youtube.com/watch?v=h_tkIpwbsxY https://www.youtube.com/watch?v=h_tkIpwbsxY I'm pretty sure he's the only person to make this topic so approachable. I'm glad he's into having fun with it. Quite refreshing!
- halis 8y agoThis book is very good. If you like Javascript and want to further your understanding of functional programming, then I would highly recommend it.
- tomrod 8y agoI wish I knew enough compsci to know why functional programming is useful. I read about half the book, and while interesting from a learning perspective I don't know where I can apply it. Context: self-taught programmer in the data science/statistical modeling world.
- charlieflowers 8y agoYou don't really need compsci to understand that. A pure function is more of a declaration of truth than a list of steps. When your whole application is made up of declarations of truth, it is simpler to reason about and rearrange. It's simply the fact that the function depends on nothing but its inputs (but includes all the surprising ramifications of that).
- steve_adams_86 8y agoSince I've started applying FP (I'm not very strict about it) I've been finding ways to reuse code more which lets me reduce my test footprint and increase the reliability of my code. I've also found it's easier to isolate my business logic without scoping it too strictly to an object or implementation, allowing me to think largely in coding to interfaces or contacts. This is totally doable with strict OO, but honestly I'm pretty lousy at that in practice. So FP has helped me with that too. I lean towards organizing my applications into very dumb objects which are supported by FP-style business logic. At a glance you can infer what's going on quite easily due to the idiomatic use of the objects, but the object orientation mostly ends there. My business logic is organized into isolated modules that are as pure as I can manage without being a nut about it. The objects recruit or are operated on by that logic, so their implementation is very light and clean as a result. Like I mentioned, tests for this kind of code are really nice. They tend to be concise. It's not perfect, but I feel like it's a way FP has greatly improved my code and what I deliver to my team in general. It's an attempt to merge the benefits of two paradigms, I suppose.
- hackermailman 8y agoRobert Harper's 'Programming in Standard ML' free pdf off his CMU page is the best intro I've found to really understand FP, goes into details and reasons, like the pattern matching material. Very concisely written and SML is like Scheme, easy to learn syntax perfect for teaching.
- allenleein 8y agoGreat book, really enjoyed. For people who wanna learn more about Functional Programming (Haskell,Purescript) from 101 to building product, I recommend this resources: FP Resources:https://github.com/functionalflow/brains/projects/9 https://github.com/functionalflow/brains/projects/9
- wodenokoto 8y agoWhy does he factor out the zero valued flock of birds variable? That seems extremely dishonest. The reason why we name variables, is so that they can hold different values. There is no guarantee that every run of the script will have the same initial variables. If it was, you might as well just type in the result.