<div dir="ltr"><div><div><div><div><div><div><div><div><div>true! no it's totally my fault, i forgot about that. I'm not exactly sure why is that, it seems slightly absurd, limiting, to me but I guess it must be something on the inside.<br><br></div>In that case, from what I know to this day, you'll have to choose either, and I know no easy way to integrate a point-free conditional choice (in other terms, to replace the guards in a pointfree manner) on one of the parameters, so I'd go for the non-pointfree style, aka your original implementation, with the guards.<br><br></div>of course we can merrily cheat:<br></div>test1arg :: (a -> b) -> (a -> b) -> (a -> Bool) -> a -> b<br></div>test1arg cond thenF elseF x<br></div> | cond x = thenF x<br></div> | otherwise = elseF x<br></div>then:<br></div>mc :: Integral a => a -> a<br></div>mc = test1arg (<100) (-10) (mc . mc . (+11))<br><div><div><div><div><div><div><br></div><div>it amounts to moving the guards into another function. the "if then else" expression is very similar of course, but doesn't allow, as far as I know, point-free style.<br><br></div><div>Anyway... all this becomes a pointless (pun unintended) search for the point-free style at all costs. I'm not sure it's generally speaking, a very good idea. Non-point-free style is perfectly good style in itself, and pointfree should be in my opinion reserved to cases where it comes naturally, where, when perhaps looking at one's definition for a function, one realizes the presence of the argument is pointless; one very random last-minute example:<br></div><div>f xs = zip [0..] xs ---> f = zip [0..]<br></div><div>also to the cases when the very definition of a function comes to one as combination of other functions. beyond that, I'd say it's mostly wasted time.<br></div><div><br></div><div>I think the question is to balance the style, to always prefer clarity to "coolness" at any rate. Sure, in many cases, a pointfree style is in my opinion much quicker to understand, much clearer. Also, pointfree style is also a very good exercise I think, that permits beginners (i put myself in it needless to say) to get a better understanding of haskell's syntax, and of the whole function paradigm in general.<br></div><div>As long as exercises in pointfree feats aren't hindering real programming, I'd say there's no problem in trying to go for it whenever it's possible. Plus in my opinion it can be fun.<br><br></div></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-04-11 16:16 GMT+02:00 mike h <span dir="ltr"><<a href="mailto:mike_k_houghton@yahoo.co.uk" target="_blank">mike_k_houghton@yahoo.co.uk</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="color:#000;background-color:#fff;font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,Sans-Serif;font-size:16px"><div><span>Hi,</span></div><div><br><span></span></div><div><span>Thanks for the comprehensive and considered answers. </span></div><div><span>Maybe I'm missing something but defining the original function to have two definitions with a different number of args in each causes a compiler error ie. doing</span></div><div><br><span></span></div><div dir="ltr">mc :: (Integral a) => a -> amc x | x < 100 = x - 10 -- 1 arg<br clear="none">mc = mc . mc . (+ 11) -- no args<br></div><div dir="ltr"><br></div><div dir="ltr">Thanks</div><div dir="ltr"><br></div><div dir="ltr"><br></div> <div><br><br></div><div style="display:block"> <div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,Sans-Serif;font-size:16px"> <div style="font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,Sans-Serif;font-size:16px"> <div dir="ltr"><font face="Arial" size="2"> On Sunday, 10 April 2016, 22:29, Silent Leaf <<a href="mailto:silent.leaf0@gmail.com" target="_blank">silent.leaf0@gmail.com</a>> wrote:<br></font></div> <br><br> <div><div><div><div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div>Mike: If you seek as I think you do, to write the function mc (partially) in point-free style, you must know this style implies no arguments, or at least not all arguments, mentioned, that is for example here:<br clear="none"></div>mc x | x < 100 = x - 10<br clear="none"></div>mc = mc . mc . (+ 11)<br clear="none"><br clear="none"></div>The second line will only be checked for pattern matching if the first one fails, so it amounts to the "otherwise" guard as here there's no pattern, so it's a bit like the pattern that always matches (mc _ = ...)<br clear="none">You'll remark I did write (mc =) and not (mc x =). Point free style amounts to describing a function through a composition of other functions, in an arguments-free way, here for example, (mc . mc . (+11)) being the composition of mc twice, with the "partially-applied" function (+11) == (\x -> x + 11) == (11+). This partially applied notation works for all operators by the way.<br clear="none"><br clear="none">And for the record, the whitespace operator is a pure myth. First you
can remove all whitespace, it still works. Second, try using the same
whitespace-induced universal right-associativity with (f a b): does it
amount to (f (a b))?<br clear="none"><br clear="none"></div></div><div>The reason for this right-associativity interpretation in (mc . mc (x + 11)) is because (.) itself is right associative: right-directed greediness could we say, in the vocabulary of regular expression. It's also the case of ($), and that's why we use it to counter the natural left associativity of function application:<br clear="none">f $ g a == f $ (g a) == ($) f (g a) == f (g a) -- (using the definition of ($) here)<br clear="none">instead of<br clear="none">f g a == (f g) a<br clear="none">without using ($).<br clear="none"><br clear="none"></div><div>The whitespace is just a meaningless character (I guess, a set of characters) used to separate juxtaposed meaningful tokens of the language when we have either (symbol,symbol) or (nonsymbol,nonsymbol), for example respectively (!! $ /= !!$) and (f g /= fg). whenever it's a nonsymbol and a symbol, whitespace is not necessary (a+, +a).<br clear="none"></div><div>Then there's the automatic, implicit function application between two juxtaposed non-symbolic tokens. But the whitespace has never been an operator of any kind, and is totally meaningless (and optional) in (mc . mc (x + 11)).<br clear="none"><br clear="none">Especially too, it's clear no whitespace survives the tokenization during the lexical phase of the (pre?) compilation, contrarily to all real operators like (+).<div><br clear="none"></div></div></div></div></div></div></div></div></div></div></div><br><div>_______________________________________________<br clear="none">Beginners mailing list<br clear="none"><a shape="rect" href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br clear="none"><a shape="rect" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br clear="none"></div><br><br></div> </div> </div> </div></div></div><br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>