In a traditional language, the obvious approach would be to sort the list and take the first k elements, but this is expensive. Let's say we want to find the k least-valued elements of an unsorted list.
Or if my problem is just that I haven't had the patience to push all the way through Real World Haskell and/or The Little Schemer or to just buckle down and write something real and complicated in a functional language, then I'll put those back on the to-do list and see what happens. But if there is some resource out there that might help someone like me bridge that gap, I'd love to hear about it.
But I've never been anywhere near the point where I've thought, "Hey, writing this in Haskell would be better!" So I feel like I'm still missing something.Īm I hoping for too much? Is the general appreciation I have for some of the main ideas most of it? It's possible that the rest - the enthusiasm I see in others that I'm missing - is some blend of elitism and Stockholm syndrome. And I keep these things in mind and use various functional-ish patterns when coding in imperative languages, especially those that have functional-ish things baked in like Python and Javascript. I see the value of a solid type system (and love that Mypy and TypeScript are here, hopefully with more to come). I see the value in throwing functions around like candy data and all of the fun and elegance that can allow. I see the value of pure functions in helping us reason about, test, and parallelize code. The moment of understanding why so many people seem to think it is the superior paradigm has never come. I've taken a course using Scheme and guided a student through an independent study learning Haskell (during which I did come to understand monads at some point). I read things like this semi-regularly, including a good chunk of Real World Haskell, a good chunk of The Little Schemer, and numerous blog posts and articles, always hoping for enlightenment. I've tried to buy into functional programming. The proposal to add a pattern-matching syntax is the single dumbest idea the js community has had in a good, oh, two weeks. But attempting to force Haskell and ML-like patterns into it without the type safety (or really, really, REALLY good test and doc coverage) is a recipe for disaster.
The only reason javascript's gotten anywhere is because it's functional "enough" to have functions as first-class citizens, which allows for callback and promise patterns, dependency injection, and all the other stuff that's the only reason it's even a basically usable language post 1998 or so. Posted by combinatorial explosion at 7:54 PM on JĪrtw: Haskell's real strength comes from its type system which lets you do cool things like throw at compilation time if there are unaccounted-for cases in a pattern matching or switch block, and option types, which are the sensible way to represent nullable values instead of javascript's 52452 different flavors of same and ill-conceived notion of "falsey". Weakly typed functional programming languages are a nightmare in comparison to ML and Haskell (and AST).
#HASKELL FUNCTIONAL PROGRAMMING AS A LIBERAL ARTS CODE#
I still have the occasional horrible flashback to my thesis research involving Lisp and code someone else wrote that would sometimes return a nested list structure, and sometimes return that nested list structure as a string. The general techniques are fantastic, they *can* work quite well on streams of data, but it's very, very easy to empower someone enthusiastic and not entirely aware of what they're doing to construct an absolute nightmare (like the novice user of C++ STL collections - good luck debugging those deeply nested list or map iterators). Functional programming has been working it's way into mainstream languages (Java, C#, more usage of that style of programming in Javascript - which, ugh - see comment on weakly typed functional languages below) for better or worse. It's not quite as pure, but it's a bit more readable/easy to get started (cue angry language bickering). If the pureness of Haskell isn't quite your thing, try ML (or it's more popular variant OCaML).