So as a part of my efforts to not just be so isolationist I'm starting to get code critiques on Haskell Cafe. It makes me proud, though, to be able to make grown men weep with the power of my unintentional obfuscation. Did I say proud? I meant mildly mortified.
Indeed though, the feedback was actually rather helpful and it made me realize something: I still naturally avoid laziness. I mean, I take advantage of the ability to define control structures via laziness, but relying on laziness to give you incremental processing of a file? I still find that a little scary & unintuitive. I feel like an ape trying to understand the proper uses of fire: not entirely cognizant of the proper outcome but instinctively aware that I could bring everything down in flames.
How do I overcome this? Experience I suppose. That and perhaps judiciously looking at the ghc-core output to understand what the compiler is really doing.
I actually have a slightly less trivial utility for generating fake subscriber profiles for testing an e-mail system I'm working on that, despite working in ~2 seconds for 10k profiles, exhausts its available memory after about 10 minutes when I try to generate 100k profiles. Yikes! So I'm guessing I'm misusing laziness somehow and building up a massive amount of thunks, and as Cee-Lo Green almost said "I ain't got no time to be thunkin' around". I want to try digging into the generated core, doing some profiling, and finding out what is really what before I ask h-cafe again. It'll put hair on my chest.
Friday, September 19, 2008
Subscribe to:
Post Comments (Atom)
3 comments:
Depending on how familiar you are with Haskell prior to the public foray, I'd suggest that you may be better served by trying to understand laziness in the abstract, rather than delving into Core just yet. You'll want to learn Core eventually, but I'd think it'd be easier to learn how laziness works first (and then learn Core to ensure that what the compiler does is what you want to happen). Core will tell you what's being done strictly and what lazily, but it probably won't help you develop intuitions about how laziness works or when you should encourage it.
Some things you may want to look into: Haskell Wikibook: Laziness, The Reverse State Monad, Chris Okasaki's thesis (and other work), and the "tying the knot" pattern which I can't seem to find a good paper on at the moment.
I wouldn't say I'm UN-familiar with Haskell, but mostly I've written fairly small projects: Pong & Tetris clones, little proof of concept pieces, exercises from programming texts.
Somewhat to my own dismay, I've realized that I've always dealt with such small programs and such limited amounts of data that I've been "doing it wrong" without ever realizing it.
I appreciate the links & will add those to my reading, thanks.
Regarding those fake email profiles. I had a similar task and this is how I done it:
http://www.haskell.org/haskellwiki/QuickCheck_as_a_test_set_generator
Post a Comment