<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><span class="Apple-style-span" style="font-size: small;">For example, which of these is easier to read?<br>
<br>
f,g :: Int -> [Int]<br><br>
h1 :: Int -> [Int]<br>
h1 x = do<br>
fx <- f x<br>
gx <- g x<br>
return (fx + gx)<br><br>
h2 :: Int -> [Int]<br>
h2 x = (+) <$> f x <*> g x<br><br>
h3 :: Int -> [Int]<br>
h3 x = f x + g x -- not legal, of course, but wouldn't it be nice if it was?<br>
</span></blockquote><div class="gmail_quote"><span class="Apple-style-span" style="font-size: small;"><br></span></div><div class="gmail_quote"><span class="Apple-style-span" style="font-size: small;">Yes, all that lifting is something that takes away lot of the beauty and simplicity of Haskell, but as far as my limited knowledge goes, I don't think this problem is easily solved :)<br>
</span></div><div class="gmail_quote"><span class="Apple-style-span" style="font-size: small;"><br></span></div><div class="gmail_quote"><span class="Apple-style-span" style="font-size: small;">Anyway, for your particular example, for newbies I guess the clearest would be:</span></div>
<div class="gmail_quote"><span class="Apple-style-span" style="font-size: small;"><br></span></div><div class="gmail_quote"><div class="gmail_quote"><span class="Apple-style-span" style="font-size: small;">h0 x = [ fx+gx | fx <- f x, gx <- g x ]</span></div>
<div><span class="Apple-style-span" style="font-size: small;"><br></span></div><div><span class="Apple-style-span" style="font-size: small;">since one must recognize that a list monad exists and what it does...</span></div>
<div><span class="Apple-style-span" style="font-size: small;"><br></span></div><div><span class="Apple-style-span" style="font-size: small;">Now, for binary operators, Thomas Davie made a nice pair of combinators on Hackage (InfixApplicative) that would allow this to become:<br>
</span></div></div></div><div class="gmail_quote"><span class="Apple-style-span" style="font-size: small;"><br></span></div><div class="gmail_quote"><span class="Apple-style-span" style="font-size: small;">h3 x = f x <^(+)^> g x</span></div>
<div class="gmail_quote"><span class="Apple-style-span" style="font-size: small;"><br></span></div><div class="gmail_quote"><span class="Apple-style-span" style="font-size: small;">But in general, I guess you have a good point...</span></div>
<div class="gmail_quote"><span class="Apple-style-span" style="font-size: small;"><br></span></div><div class="gmail_quote"><span class="Apple-style-span" style="font-size: small;"><br></span></div><div class="gmail_quote">
<span class="Apple-style-span" style="font-size: small;"> <br></span></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<span class="Apple-style-span" style="font-size: small;"><br>
Of course this raises problems of order of evaluation, etc, but as<br>
long as such things were well-defined, that seems fine. If you want<br>
finer control, you can always go back to more verbose syntax. These<br>
cases are dominated by the cases where you simply don't care!<br><br>
This said, I don't want to sound overly negative; all of this pain is<br>
*worth* the correctness guarantees that I get when writing in Haskell.<br>
I just wish I could get the same guarantees with less pain!<br><br>
-- ryan<br><br><br>
2009/1/10 Peter Verswyvelen <
</span><a href="mailto:bugfact@gmail.com"><span class="Apple-style-span" style="font-size: small;">bugfact@gmail.com</span></a><span class="Apple-style-span" style="font-size: small;">>:<br>
</span><div><div></div><div class="Wj3C7c"><span class="Apple-style-span" style="font-size: small;">> Related to this issue, I have a question here.<br>
> I might be wrong, but it seems to me that some Haskellers don't like<br>
> writing monads (with do notation) or arrows (with proc sugar) because of the<br>
> fact they have to abandon the typical applicative syntax, which is so close<br>
> to the beautiful lambda calculus core. Or is it maybe because some people<br>
> choose monads were the less linear applicative style could be used instead,<br>
> so the choice of monads is not always appropriate.<br>
> Haskell is full of little hardcoded syntax extensions: list notation<br>
> syntactic, list comprehensions, and even operator precedence that reduces<br>
> the need for parentheses, etc...<br>
><br>
> Of course IMHO the syntactic sugar is needed, e.g. a Yampa game written<br>
> without the arrows syntax would be incomprehensible for the average<br>
> programmer. But one could claim that this syntactic sugar hides what is<br>
> really going on under the hood, so for newcomers these extensions might make<br>
> it harder. It could also feel like a hack, a failure to keep things as<br>
> simple as possible yet elegant.<br>
> Some people I talked with like that about the Scheme/ & LISP languages: the<br>
> syntax remains ultimately close to the core, with very little hardcoded<br>
> syntactic extensions. And when one wants to add syntactic extensions, one<br>
> uses syntactic macros.<br>
> I'm not sure what others feel about the hardcoded syntax extensions in<br>
> Haskell...<br>
><br>
> Personally I'm not that much of a purist, I'm an old school hacker that<br>
> mainly needs to get the job done. I like the syntax extensions in Haskell<br>
> (and even C#/F# ;) because they let me write code shorter and clearer...<br>
> On Fri, Jan 9, 2009 at 4:07 AM, Neal Alexander <</span><a href="mailto:wqeqweuqy@hotmail.com"><span class="Apple-style-span" style="font-size: small;">wqeqweuqy@hotmail.com</span></a><span class="Apple-style-span" style="font-size: small;">><br>
> wrote:<br>
>><br>
>> Ertugrul Soeylemez wrote:<br>
>>><br>
>>> Hello fellow Haskellers,<br>
>>><br>
>>> When I read questions from Haskell beginners, it somehow seems like they<br>
>>> try to avoid monads and view them as a last resort, if there is no easy<br>
>>> non-monadic way. I'm really sure that the cause for this is that most<br>
>>> tutorials deal with monads very sparingly and mostly in the context of<br>
>>> input/output. Also usually monads are associated with the do-notation,<br>
>>> which makes them appear even more special, although there is really<br>
>>> nothing special about them.<br>
>>><br>
>><br>
>> Yea, i was the same way when i started learning Haskell. I understood how<br>
>> Monads worked, and what the motivation was for them, but not why i would<br>
>> want to restructure code to use them in specific instances.<br>
>><br>
>> "Why should i care about monads when i can use Arrows or (.)" was also a<br>
>> factor.<br>
>><br>
>> Its kinda like getting advice from an adult as a child. You have no<br>
>> particular reason to distrust the advice, but the value of it doesn't set in<br>
>> until something happens to you first hand to verify it.<br>
>><br>
>> For me the turning point was writing some code that needed to handle<br>
>> running code locally/remotely in a transparent manner.<br>
>><br>
>> Maybe having a list of real-world usage scenarios or exercises on the wiki<br>
>> may help.<br>
>><br>
>> ______________________________ _________________<br>
>> Haskell-Cafe mailing list<br>
>> </span><a href="mailto:Haskell-Cafe@haskell.org"><span class="Apple-style-span" style="font-size: small;">Haskell-Cafe@haskell.org</span></a><span class="Apple-style-span" style="font-size: small;"><br>
>> </span><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank"><span class="Apple-style-span" style="font-size: small;">http://www.haskell.org/</span><span class="Apple-style-span" style="font-size: small;">mailman/listinfo/haskell-cafe</span></a><span class="Apple-style-span" style="font-size: small;"><br>
><br>
><br>
</span></div></div><span class="Apple-style-span" style="font-size: small;">> ______________________________</span><span class="Apple-style-span" style="font-size: small;">_________________<br>
</span><div><div></div><div class="Wj3C7c"><span class="Apple-style-span" style="font-size: small;">> Haskell-Cafe mailing list<br>
> </span><a href="mailto:Haskell-Cafe@haskell.org"><span class="Apple-style-span" style="font-size: small;">Haskell-Cafe@haskell.org</span></a><span class="Apple-style-span" style="font-size: small;"><br>
> </span><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank"><span class="Apple-style-span" style="font-size: small;">http://www.haskell.org/</span><span class="Apple-style-span" style="font-size: small;">mailman/listinfo/haskell-cafe</span></a><span class="Apple-style-span" style="font-size: small;"><br>
><br>
><br>
</span></div></div></blockquote></div><br>