<div class="im" style="font-family:arial,sans-serif;font-size:13px">> ><br>> > g = (\x -> f x 1 2 3)<br>></div><span style="font-family:arial,sans-serif;font-size:13px">> Yes, a lambda is the only way to do it.</span><br>
<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">This is not exactly the same thing, but if you have a function that accepts only two arguments, you can use `flip` to partially apply with the other one:</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">f a b = a ++ b</span></div><div><span style="font-family:arial,sans-serif;font-size:13px">g = (flip f) "xyz"</span><br>
</div><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">g "abc" -- "abcxyz"</span></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br>
</span></div><div><span style="font-family:arial,sans-serif;font-size:13px">To extend that to functions with more parameters, you'd have to create an equivalent of `flip` for each arity, and the desired permutations might be more complicated than just reversing them. Still, in the two-argument case, flip can often be cleaner than a lambda.</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">Peter</span></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 3 December 2012 12:53, Brent Yorgey <span dir="ltr"><<a href="mailto:byorgey@seas.upenn.edu" target="_blank">byorgey@seas.upenn.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Mon, Dec 03, 2012 at 12:28:08PM +0000, Miguel Negrao wrote:<br>
> Hi list,<br>
><br>
> Is there a syntax in Haskell for partial application that would be something like this the following ?<br>
><br>
> f a b c d = a +b+ c+ d<br>
><br>
> g = f _ 1 2 3<br>
><br>
> or the only way to do it is like below ?<br>
><br>
> g = (\x -> f x 1 2 3)<br>
<br>
</div>Yes, a lambda is the only way to do it.<br>
<div class="im"><br>
> Also, hlint complains about top-level functions without type even<br>
> if they are not exported out of the corresponding module. Is is<br>
> really bad style not put type signatures in all top-level functions<br>
> ? I really like the fact that haskell takes care of the type<br>
> signatures for me.<br>
<br>
</div>Yes, it is bad style. Let me give you two reasons why I always<br>
encourage putting type signatures on all top-level functions. Whether<br>
they are exported or not really makes no difference.<br>
<br>
1. Writing the type signature for a function *first*, before<br>
implementing it, really helps a LOT in clarifying things in your<br>
own mind. If you cannot write down the intended type of a<br>
function then you do not understand what it is supposed to do.<br>
If you do not understand what it is supposed to do then how do<br>
you expect to be able to implement it?<br>
<br>
2. Suppose you make a mistake when implementing a function. If you<br>
don't give a type signature, it's possible that GHC will infer<br>
some type for it anyway (but not the type you intended!). Now<br>
you will not get an error until further down the line when you<br>
use that function somewhere else. And what's more, the error<br>
will not tell you anything about the real problem. It will just<br>
say "X does not match Y on line 297" and you will have to do a<br>
lot of work to figure out that the real problem is that you<br>
messed up in implementing function foo on line 43. But if you<br>
had put a type signature on foo in the first place, you would<br>
have gotten an error immediately.<br>
<span class="HOEnZb"><font color="#888888"><br>
-Brent<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</div></div></blockquote></div><br></div>