[Haskell-beginners] Is "step by step" the most natural style of
mpm at alumni.caltech.edu
Tue Oct 20 04:52:31 EDT 2009
Daniel Fischer wrote:
> Am Dienstag 20 Oktober 2009 04:48:50 schrieb Michael Mossey:
>> Eliminating variables and working with function combinations has benefits.
> But it's not unconditionally a good thing. If you exaggerate it, it's pure obfuscation.
> Nevertheless, playing around with eliminating variables and using combinators
> even beyond the border of obfuscation is a good exercise.
> You gain understanding and a feeling of when it's better to stop by that.
I think I understand.
Another way to put my point is that learning Haskell has trained my eye to
notice when a particular variable is flopping around in six different
places. I programmed for twenty years or more in imperative languages (in a
business setting, not academia) and no one ever said, "Hey we've got too
many repetitions of x! Let's see what the underlying abstraction REALLY is."
>> The one suggestion I've seen here that seems to be right on the money is
>> liftM2 (&&) (< 0.5) (> -0.5)
> May I offer
> (&&) <$> (< 0.5) <*> (> -0.5)
> ? It works on Applicative Functors (doesn't need the full force of Monads).
>> Although that might seem less clear to a beginner, it is actually _more_
>> clear than the lambda function in some ways. It's easier to work with proof
>> at a more abstract level like this, and strange as it may seem, what I seem
>> to observe in expert users of Haskell is that their brains will pick up
>> what this is doing faster than the lambda function.
> In this small example, both are immediately clear, you need more complicated lambda
> expressions to get a measurable difference :)
Yeah, pretty small example, but based on what I've read in "Real World
Haskell" and "Craft of Functional Programming," the authors find a lot of
"strange-looking" (to the imperative programmer's eye) function combinators
to be the most natural way of expressing the solution, and from time to
time I find my thoughts aligning with them, and I realize how much less
thought it takes.
This raises the question: is "step by step" thinking the "most natural" way
to think about a mathematical problem? My hunch is "no." There are multiple
modes of thought, and no reason to eliminate cognitive models that involve
imagery, imaginary things moving and sliding through space... or analogies
to the more common physical world... or the list is endless. I like the way
Haskell resonates with a larger set of thinking styles.
More information about the Beginners