7 ms·
Functionally Solving Problems With Haskell
- tel 13y agoWhile LYAH is a lot of fun, if you've gotten your feet wet with Haskell for a while and want to see some really powerful examples of "functionally solving problems" I cannot recommend more highly Richard Bird's "Pearls of Functional Algorithm Design"[0]. All of the "Functional Pearls" papers are worth a read, but Bird's book is such a compressed, convenient, powerful collection of advanced functional problem solving style that I think anyone interested in "thinking" functionally should strive to read it. It's not exactly for the faint of heart, to be clear. Bird's idea is that we can establish certain mathematical rules which allow us to transform "the simplest thing which could possibly be correct" to an efficient program through a series of steps, each one maintaining correctness as an invariant. [0] http://www.amazon.com/Pearls-Functional-Algorithm-Design-Richard/dp/0521513383 http://www.amazon.com/Pearls-Functional-Algorithm-Design-Ric...
- dfan 13y agoHeartily seconded.
- sordina 13y agoThe majority of this book is also highly portable. The techniques can be applied across languages very easily, although, the Haskell implementations are very elegant.
- tel 13y agoI would say that's true in so far as your language you're porting to has a preponderance of pure functionality and notions of real mathematical "variables". Without those it'll be hard to get any semblance of equational reasoning to work out.
- dcre 13y agoThanks, it looks great.
- zmanian 13y agoConfused why a random chapter from the wonderful LYAH is on the top of Hacker News....
- Lambdanaut 13y agoYeah. This is annoying. I mean, I can't give an objective measure as to why this is a tragedy, but I feel like it is, you know? Let's just all go through our favorite 3 year old books and post HN articles about every chapter that strikes our fancy why don't we?
- krick 13y agoIf it actually strikes your fancy, why not? But I also don't understand why this specific chapter and what poster wanted to show us really.
- Lambdanaut 13y agoI guess that's it. It feels very arbitrary and unfocused, and I question the specific value. I'd feel awful yelling "karma whore" in a crowded theater without proper evidence, but if it looks and smells like one...
- abraxasz 13y agoI read the book a while back and it is absolutely fantastic. What I understand about monads, I learnt it from this book (no other exposition of monads ever made sense to me), and I particularly like his progression functors -> applicative functors -> monads. I think it's the clearest way to proceed (certainly helped me a lot anyways)
- coolsunglasses 13y agoWhen I teach Haskell, I like to take a diversion from Applicatives to Monoids before going to Monads. Understanding join is pretty valuable for understanding Monads too.
- tel 13y agoYou can do Applicative -> Alternative and study Alternatives as Monoids of Applicatives and then lay on the difference between (<*>) and (<>) as producing a seminearring! And then go study Monads because why not. They're kind of cool, too.
- coolsunglasses 13y agoActually you just reminded me that I need to explain sums and products in terms of a seminearring.
- bsamuels 13y agoAs a side-note, if you want to get into functional programming but don't want to make the full leap into "PURE EVERYTHING MUST STAY CLEAN DONT BREAK THE RULES" world of Haskell, F# is another excellent choice for a beginner functional lang. You can program in either OOP or functional style, letting you take your time with the transition. I also toot F#'s horn because it has an amazing resource for learning how to use functional style in your programs: http://fsharpforfunandprofit.com/site-contents/ http://fsharpforfunandprofit.com/site-contents/ A few pages on that site did more for me regarding functional programming than the entirety of LYAH did, and it also has a very nice monad tutorial: http://fsharpforfunandprofit.com/posts/computation-expressions-intro/ http://fsharpforfunandprofit.com/posts/computation-expressio...
- stesch 13y agoNot everybody uses Windows. F# is a .NET language.
- bsamuels 13y agoF#'s compiler is open source. The language can compile into CIL, javascript, and a handful of other build targets.
- liammclennan 13y ago"can compile into ... javascript" I don't believe this is true, at least not easily.
- MichaelGG 13y agoPit and WebSharper are two examples that can turn F# into JS.
- Tehnix 13y agoHeard about Mono? http://fsharp.org/use/mac/ http://fsharp.org/use/mac/ http://fsharp.org/use/linux/ http://fsharp.org/use/linux/
- stesch 13y agoOh, I remember. That's where I stopped reading the book.
- brianmwaters_hn 13y agoDid anybody else notice what is written on the upside-down calculator about 1/8 down the page?
- quchen 13y agoStuff like this is all over LYAH, silly hidden unrelated jokes. Read the tree in the Zipper chapter :-) http://learnyouahaskell.com/zippers http://learnyouahaskell.com/zippers
- groovy2shoes 13y agoAlso, be sure to read the tree with a pre-order traversal. In-order and post-order traversals yield a nonsensical string.
- dbbolton 13y agoIf you just want to play around with RPN a bit, I made a simple (regex-based) RPN calculating Perl script a while back: https://github.com/dbb/math-scripts/blob/master/rpn_calc.pl https://github.com/dbb/math-scripts/blob/master/rpn_calc.pl
- ardz 13y agoAnother Haskell SPAM. How can anyone seriously code in a language which introduces new kind of bugs which cannot be detected by any test until running in production on real data when it is already too late?
- phaer 13y ago[citation needed]. Seriously, which kind of bugs are you referring to?
- ardz 13y agoReally? http://stackoverflow.com/questions/21097051/kinds-of-bugs-that-are-more-likely-prone-in-haskell-programs-than-in-other-langu http://stackoverflow.com/questions/21097051/kinds-of-bugs-th...
- phaer 13y agoI am sorry, I fail to see a bug there which "cannot be detected by any test until running in production on real data when it is already too late". It's mainly problems with lazy IO which should be detected by unit tests using test data, right? The first answer is actually a nasty bug, but you should probably not deploy code which sends your test suite into an endless loop no matter in which language it is written. Yes, Haskell does not solve all programming problems, but I don't see anything which could not be found by testing here.
- ardz 13y agoUnit test will not detect everything. You need real data under heavy load for Haskell. This is a _fact_. Most of you here should stop writing BS about Haskell and how it is going to save the world. > I never said that. Your argument was that this is specific to Haskell which is not. It is specific to lazily evaluated languages, especially Haskell. To test Haskell program you will need a real environment under heavy load - maybe Google or Amazon could afford it. Tiny unit tests which are perfect for strictly evaluated languages won't detect these kid of bugs.
- maxyb 13y agoThe link is a chapter from "Learn You a Haskell for Great Good", which I recommend a lot if you want to learn Haskell. However, if you click through to the table of contents, you'll see immediately one of my problems with Haskell as a language: guess in what chapter you finally get to write hello world?
- judk 13y agomain = print "Hello, world!" Is that really interesting enough to rush to?
- nbouscal 13y agoYour problem with Haskell as a language is the pedagogical approach taken by the author of one of the books about it?
- quchen 13y agoHello World is mostly the most primitive program you can write in order to check whether your compiler/interpreter is working properly, so you can get started. In case of LYAH (or Haskell in general) you have GHCi at hand, an interactive interpreter. That's what LYAH sets up in the very first chapter, and uses throughout the rest of the book.