Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: ($) operator (Daniel Fischer) 2. [fschwi...@localhost: Re: [Haskell-beginners] ($) operator] (Frank Schwidom) 3. Re: ($) operator (Brent Yorgey) 4. Re: ($) operator (David Morse) 5. Re: ($) operator (Jan Jakubuv) 6. Re: ($) operator (Frank Schwidom) 7. Re: ($) operator (Brent Yorgey) 8. Re: ($) operator (Dave Bayer) 9. Calculating Time Complexity (Matthew J. Williams) 10. Re: Calculating Time Complexity (Krzysztof Skrz?tnicki) ---------------------------------------------------------------------- Message: 1 Date: Sat, 24 Jan 2009 21:09:31 +0100 From: Daniel Fischer <daniel.is.fisc...@web.de> Subject: Re: [Haskell-beginners] ($) operator To: John Hartnup <john.hart...@gmail.com>, beginners@haskell.org Message-ID: <200901242109.31199.daniel.is.fisc...@web.de> Content-Type: text/plain; charset="iso-8859-1" Am Samstag, 24. Januar 2009 20:37 schrieb John Hartnup: > Hi. > > I'm working through Real World Haskell, and although it's going well > (I just finished the exercise to write a glob matcher without using a > regex library, and I'm pleased as punch), I keep seeing the ($) > operator, and I'm not sure I understand its use. If the book explains > it, I've been unable to find it. > > Empirically, it seems like: > a $ b c d e f > .. is equivalent to .. > a (b c d e f) Indeed. ($) is the function application operator, f $ x = f x , so a $ b c d e f is equivalent to a (b c d e f) and a $ b c $ d e f to a (b c (d e f)). > > But is that its only purpose? To placate the LISP haters by removing > parentheses? More or less. Although the idea was more to enhance readability than placating LISP haters :) It's also handy to pass to some higher order functions, although offhand I can't think of any situation where you couldn't pass id instead of ($). > > (1 +) 2 does the same thing as (1 +) $ 2, and has the same type. > > Am I missing something? > > Thanks, > John ------------------------------ Message: 2 Date: Sat, 24 Jan 2009 22:14:02 +0000 From: Frank Schwidom <schwi...@gmx.net> Subject: [fschwi...@localhost: Re: [Haskell-beginners] ($) operator] To: beginners@haskell.org Message-ID: <20090124221402.gb4...@bigbox> Content-Type: text/plain; charset=us-ascii ----- Forwarded message from Frank Schwidom <fschwi...@localhost> ----- Date: Sat, 24 Jan 2009 21:40:54 +0000 From: Frank Schwidom <fschwi...@localhost> To: John Hartnup <john.hart...@gmail.com> Subject: Re: [Haskell-beginners] ($) operator Message-ID: <20090124214053.ga4...@bigbox> References: <6c1ba2fc0901241137x242cf4b4w2398896af45ae...@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6c1ba2fc0901241137x242cf4b4w2398896af45ae...@mail.gmail.com> User-Agent: Mutt/1.5.16 (2007-06-09) Status: RO On Sat, Jan 24, 2009 at 07:37:29PM +0000, John Hartnup wrote: > Hi. > > I'm working through Real World Haskell, and although it's going well > (I just finished the exercise to write a glob matcher without using a > regex library, and I'm pleased as punch), I keep seeing the ($) > operator, and I'm not sure I understand its use. If the book explains > it, I've been unable to find it. > > Empirically, it seems like: > a $ b c d e f > .. is equivalent to .. > a (b c d e f) > > But is that it's only purpose? To placate the LISP haters by removing > parentheses? > > (1 +) 2 does the same thing as (1 +) $ 2, and has the same type. > > Am I missing something? > > Thanks, > John > > > -- > "There is no way to peace; peace is the way" > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners maybe can this answer your question: A: ((==) True) (1 == 1) -- won't work: ((==) True) 1 == 1 => ((==) True) ((==) 1 1) -- won't work: ((==) True) (==) 1 1 => ((==) True) $ (==) 1 1 => ((==) True) $ 1 == 1 Regards ----- End forwarded message ----- ------------------------------ Message: 3 Date: Sat, 24 Jan 2009 17:52:37 -0500 From: Brent Yorgey <byor...@seas.upenn.edu> Subject: Re: [Haskell-beginners] ($) operator To: beginners@haskell.org Message-ID: <20090124225237.ga13...@seas.upenn.edu> Content-Type: text/plain; charset=us-ascii On Sat, Jan 24, 2009 at 07:37:29PM +0000, John Hartnup wrote: > Hi. > > I'm working through Real World Haskell, and although it's going well > (I just finished the exercise to write a glob matcher without using a > regex library, and I'm pleased as punch), I keep seeing the ($) > operator, and I'm not sure I understand its use. If the book explains > it, I've been unable to find it. > > Empirically, it seems like: > a $ b c d e f > .. is equivalent to .. > a (b c d e f) > > But is that it's only purpose? To placate the LISP haters by removing > parentheses? > > (1 +) 2 does the same thing as (1 +) $ 2, and has the same type. > > Am I missing something? More generally, in a language with first-class and higher-order functions like Haskell, it's simply useful to have a function which performs function application. For example, one place that ($) comes in handy is when applying each function in a list of functions to a single input value. Using ($) you can just write something like map ($5) [(+1), (^2), abs] which evaluates to [6,25,5]. -Brent ------------------------------ Message: 4 Date: Sun, 25 Jan 2009 00:25:29 -0500 From: David Morse <dcmo...@gmail.com> Subject: Re: [Haskell-beginners] ($) operator To: beginners@haskell.org Message-ID: <11f192740901242125l22a7d8f1i9ccf0bd9dbcf3...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 They definitely dropped the ball on introducing '$'. I think you just hit the seam between two of the authors, and it fell through the cracks. ------------------------------ Message: 5 Date: Sun, 25 Jan 2009 12:45:03 +0000 From: Jan Jakubuv <jaku...@gmail.com> Subject: Re: [Haskell-beginners] ($) operator To: John Hartnup <john.hart...@gmail.com> Cc: beginners@haskell.org Message-ID: <d4a7b1730901250445t35b10e42wbb1a446f0d6d...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 2009/1/24 John Hartnup <john.hart...@gmail.com>: > > But is that it's only purpose? To placate the LISP haters by removing > parentheses? > Also one important difference is that the standard application operator (space) associates to the left while $ associates to the right. It says how missing parenthesis are filled in. For example (a b c d e) stands for ((((a b) c) d) e) while (a $ b $ c $ d $ e) stands for (a (b (c (d e)))) Sometimes you need the former behavior sometimes the later. The $ is useful for example when an argument to an unary function is itself a function application. For example you can write filter (<4) $ map (+1) $ [100,99,1,2,3,4] In this case you can think of $ to be like a "unix pipe". Sincerely, jan. ------------------------------ Message: 6 Date: Sun, 25 Jan 2009 14:25:03 +0000 From: Frank Schwidom <schwi...@gmx.net> Subject: Re: [Haskell-beginners] ($) operator To: beginners@haskell.org Message-ID: <20090125142503.ga4...@bigbox> Content-Type: text/plain; charset=us-ascii On Sat, Jan 24, 2009 at 07:37:29PM +0000, John Hartnup wrote: > Hi. > > I'm working through Real World Haskell, and although it's going well > (I just finished the exercise to write a glob matcher without using a > regex library, and I'm pleased as punch), I keep seeing the ($) > operator, and I'm not sure I understand its use. If the book explains > it, I've been unable to find it. > > Empirically, it seems like: > a $ b c d e f > .. is equivalent to .. > a (b c d e f) > > But is that it's only purpose? To placate the LISP haters by removing > parentheses? > > (1 +) 2 does the same thing as (1 +) $ 2, and has the same type. > > Am I missing something? > > Thanks, > John I made some Examples for better understanding: -- creating an $ like function: f g x = (g x) -- some tests comparing $ with f: 5 == ($ 2) (+ 3) 5 == (`f` 2) (+ 3) 5 == (\x -> (($) x 2)) (+ 3) 5 == (\x -> (f x 2)) (+ 3) Regards ------------------------------ Message: 7 Date: Sun, 25 Jan 2009 09:12:06 -0500 From: Brent Yorgey <byor...@seas.upenn.edu> Subject: Re: [Haskell-beginners] ($) operator To: John Hartnup <john.hart...@gmail.com> Cc: beginners@haskell.org Message-ID: <20090125141206.ga18...@seas.upenn.edu> Content-Type: text/plain; charset=us-ascii On Sun, Jan 25, 2009 at 05:34:35AM +0000, John Hartnup wrote: > 2009/1/24 Brent Yorgey <byor...@seas.upenn.edu>: > > > > > map ($5) [(+1), (^2), abs] > > > > which evaluates to [6,25,5]. > > > > Just to check I understand correctly - you're using ($) to 'promote' > an expression into a function, in order that it may be used in higher > order functions? In this case, I'm using ($) to *make* a higher-order function---($5) is a function which takes its argument (which must be a function) and applies it to 5. (I'm assuming you're familiar with 'operator sections', if you aren't I can explain that too.) -Brent ------------------------------ Message: 8 Date: Sun, 25 Jan 2009 09:13:41 -0500 From: Dave Bayer <ba...@cpw.math.columbia.edu> Subject: Re: [Haskell-beginners] ($) operator To: beginners@haskell.org Message-ID: <f79252ae-c2ce-4a89-bcd7-7fbeeebad...@math.columbia.edu> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes 2009/1/24 John Hartnup <john.hart...@gmail.com>: > But is that it's only purpose? To placate the LISP haters by removing > parentheses? On Jan 25, 2009, at 12:25 AM, David Morse wrote: > They definitely dropped the ball on introducing '$'. I think you just > hit the seam between two of the authors, and it fell through the > cracks. Haskell isn't Cobol, but in comparison with the lambda calculus, it flows a bit better like a natural language. '$' helps with this. For example, in the line > mempty = en $ en [] ...one clearly doesn't need to use $, parenthesizing (en []) has the same meaning. However, reading left-to-right, the $ coaxes one into dropping top-down into a new view of the line, partially abstracting out or forgetting what came before, without having to maintain a mental stack and brace oneself for the closing ). I've read books on numeracy and vision, that present the same conclusion: As our brain evolved new systems for seeing or counting, the old systems didn't get thrown out, they got buried by the new layers, but they're still wired in. Part of our reaction to a line of lisp that ends in seven )))))) is no different than a pigeon or a horse seeing the same number of objects; we're not sure. Then for us a new linguistic layer kicks in, "I can see two groups of three, that's even" and we rise above the animals, but our single conscious core got hijacked to sort this out. People take the ergonomics of cockpit design very seriously, to reduce the cognitive load on pilots in emergencies. On Apollo 13, they nearly blew it by flipping a switch the wrong way. I fly a lot, so I'm very grateful that the "purists" that gravitate to math and computer science aren't instead in ergonomic design. I actually love lisp, or more precisely Scheme. I came back to Haskell for strong typing and class abstractions; Haskell more directly supports making a theory about what one is coding. In order to use Scheme, I had to defang it of its parentheses. I didn't believe that any of the web proposals for this saw actual use, so I rolled my own preprocessor, using indentation to indicate outline structure, and using '|' roughly as Haskell uses '$'. There are other issues one inevitably faces, e.g. missing starts to outline levels, but I came to love '$' as Haskell uses it. Some people develop a point-free style in Haskell, e.g. > blah foo . blah . blah foo foo . blah and different people write code that piles up uses of '$' e.g. > blah foo $ blah $ blah foo foo $ blah With decent syntax coloring the second line can be given as light a touch as the first. Ultimately, '$' helps mitigate a left / right tension in Haskell that exists in all languages, and in algebra itself. In algebra, "f g" can mean either "f then g" or "g then f". It means "g then f" in any situation crippled by the ancestry of the function composition "f(g(x))", and it means "f then g" any time one has the free choice of easier ergonomics in a culture that reads left to right. Quick, ten times, work out out the permutation cycle product > (1 2 3) (2 3 4 5) (3 4 5 6) (4 5 6 2) (5 6 1 2) (1 2 3) (2 3 4 5) > (3 4 5 6) (4 5 6 2) (5 6 1 2) under each assumption for the order of operations. One wraps around through parentheses either way, but using the "f then g" convention, all other scanning is consistently left to right, not flitting back and forth like a deranged water bug. Now try composing a complex set of type signatures for Haskell functions. Do you feel like a deranged water bug? The arrows go the wrong way, don't they! You'd be playing a nice game of dominoes, canceling off neighbors and so forth, if the arrows went the other way. So Haskell doesn't have its left / right tension completely worked out, but I'd say '$' isn't part of the problem, it's part of the solution. ------------------------------ Message: 9 Date: Mon, 26 Jan 2009 00:04:48 +0000 From: "Matthew J. Williams" <matthewjwillia...@googlemail.com> Subject: [Haskell-beginners] Calculating Time Complexity To: beginners@haskell.org Message-ID: <497cfe10.0c53300a.065a.ffff8...@mx.google.com> Content-Type: text/plain; charset="us-ascii"; format=flowed Dear all, In general terms, how would one calculate the time complexity of a given algorithm? Feel free to make use of my pseudo code in your answer: /* input: 2-D array A of size n by n output: a number max */ Max := 0 For i := 1 to n sum := 0 For j := 1 to n sum := sum + A[i][j] End for If sum > max then max := sum End for Output max Sincerely Matthew J. Williams ------------------------------ Message: 10 Date: Mon, 26 Jan 2009 01:51:51 +0100 From: Krzysztof Skrz?tnicki <gte...@gmail.com> Subject: Re: [Haskell-beginners] Calculating Time Complexity To: "Matthew J. Williams" <matthewjwillia...@googlemail.com> Cc: beginners@haskell.org Message-ID: <220e47b40901251651j1af2c6afteeb2e10b52f19...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" On Mon, Jan 26, 2009 at 01:04, Matthew J. Williams < matthewjwillia...@googlemail.com> wrote: > Dear all, > > In general terms, how would one calculate the time complexity of a given > algorithm? I would count most significant operations. The result is Theta(n^2) (see http://en.wikipedia.org/wiki/Big_O_notation for definition of Big Theta notation). Feel free to make use of my pseudo code in your answer: > > /* input: > 2-D array A of size n by n > output: a number max */ > Max := 0 > For i := 1 to n > sum := 0 > For j := 1 to n > sum := sum + A[i][j] > End for > If sum > max then max := sum > End for > Output max > > Christopher SkrzÄtnicki -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090126/6e10550a/attachment.htm ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 7, Issue 20 ****************************************