[Haskell-beginners] Re: mayBe stuck
Dean Herington
heringtonlacey at mindspring.com
Sat Aug 7 02:05:54 EDT 2010
At 11:04 AM -0700 8/6/10, prad wrote:
>On Fri, 6 Aug 2010 03:43:30 -0400
>Dean Herington <heringtonlacey at mindspring.com> wrote:
>
>> I would write something like:
>>
>> br [] = []
>> br ss = let (h, t) = break eqD ss
>> in h : case t of
>> [] -> []
>> _ : t -> br t
>>
>thx dean. that certainly looks cleaner than mine, but i'm not sure i
>have seen this construct before.
>
>i thought let/in was used like this:
>
>aaa = let y = 1+2
> z = 4+6
> in y+z
>
>which is like
>
>aaa = y + z
> where y = 1+2
> z = 4+6
>
>in other words, you just define the parts first and use the "in" to
>define the main expression.
>
>but here it seems you are defining what appears to be the main item
>let (h,t) = break eqD ss
>to get the tuple parts and then forming your array (which really is
>the main item) using these parts as
>h : t
>with t being given 2 options.
>
>this is very interesting to me as i had not seen such a construct
>before.
Choosing between `let` and `where` is usually a matter of taste. I
use both, depending on whether I think it's clearer to present the
logic "bottom-up" or "top-down". Here's the `where`-style equivalent
of the `let` version:
br [] = []
br ss = h : case t of
[] -> []
_ : t' -> br t'
where (h, t) = break eqD ss
For a reason I probably can't articulate well, I find the `let`
version more readable in this case. Perhaps it's because I
understand the function as (1) `break`ing on '%', then (2) dealing
with the details of recursing.
Cheers,
Dean
More information about the Beginners
mailing list