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: Count how often a menu has been selected (Felipe Lessa) 2. Re: haskell variables - or not (dukeofp...@ml1.net) 3. Re: haskell variables - or not (Kyle Murphy) 4. Sidebar to variables (Duke Normandin) 5. Re: Count how often a menu has been selected (Thomas Friedrich) 6. Re: Sidebar to variables (Thomas Davie) 7. Re: Count how often a menu has been selected (Felipe Lessa) 8. Re: Count how often a menu has been selected (Bernhard Lehnert) 9. Re: Sidebar to variables (Duke Normandin) ---------------------------------------------------------------------- Message: 1 Date: Sat, 25 Jul 2009 09:00:22 -0300 From: Felipe Lessa <felipe.le...@gmail.com> Subject: Re: [Haskell-beginners] Count how often a menu has been selected To: beginners@haskell.org Message-ID: <20090725120022.ga13...@kira.casa> Content-Type: text/plain; charset=us-ascii On Sat, Jul 25, 2009 at 01:10:02PM +0200, Bernhard Lehnert wrote: > let a = 0 > onActivateLeaf menuAddOne $ do > let a = a+1 > print a If you want variables in the impure sense, use IORefs. import Data.IORef ... a <- newIORef 0 onActivateLeaf menuAddOne $ do modifyIORef a (+1) print a -- Felipe. ------------------------------ Message: 2 Date: Sat, 25 Jul 2009 06:32:21 -0600 (MDT) From: dukeofp...@ml1.net Subject: Re: [Haskell-beginners] haskell variables - or not To: beginners@haskell.org Message-ID: <alpine.osx.2.00.0907250627490....@q75-154-124-54.noufvn.gryhf.arg> Content-Type: TEXT/PLAIN; charset=US-ASCII On Fri, 24 Jul 2009, Duke Normandin wrote: > Hello.... > > I'm 2 days into Haskell. NOT new to Perl, PHP, M(umps), TCL, newLISP. I'm > using "YAHT.pdf" as an intro to Haskell. Here's a quote: > > [quote] > ... if you have a value x, you must not think of x as a register, a > memory location or anything else of that nature. x is simply a name, just as > Hal is my name. You cannot arbitrarily decide to store a different person in > my name any more than you can arbitrarily decide to store a different value in > x. This means that code that might look like the following C code is invalid > (and has no counterpart) in Haskell: > > int x = 5; > [/quote] > > So is fair to say that an expression in Haskell like: > > x = 5 > > is more like a constant in imperative languages - say Perl? E.g. > > use constant SECONDS_PER_DAY => 86400; > -- > duke Thanks to all the responders!! --Thomas F. > You will get the idea in a couple of days. I am sure. Maybe next week! I'm going fly-fishing for trout on the weekend, as is my usual practice here in the Alberta (Canada) foothills ;) -- Kyle M. & Thomas D. What I gather from your replies is that the only "true" variables in Haskell are the args passed to a function. Is that correct? ...and further, that what sometimes appears to be a variable to an "unwashed" imperative programmer", is really a function with no arguments, returning a "constant" value. How did I do? -- duke ------------------------------ Message: 3 Date: Sat, 25 Jul 2009 09:00:28 -0400 From: Kyle Murphy <orc...@gmail.com> Subject: Re: [Haskell-beginners] haskell variables - or not To: beginners@haskell.org Message-ID: <2db78cee0907250600v3147dc95j6b85f1b1f0e64...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" On Sat, Jul 25, 2009 at 8:32 AM, <dukeofp...@ml1.net> wrote: > On Fri, 24 Jul 2009, Duke Normandin wrote: > > > Hello.... > > > > I'm 2 days into Haskell. NOT new to Perl, PHP, M(umps), TCL, newLISP. I'm > > using "YAHT.pdf" as an intro to Haskell. Here's a quote: > > > > [quote] > > ... if you have a value x, you must not think of x as a register, a > > memory location or anything else of that nature. x is simply a name, just > as > > Hal is my name. You cannot arbitrarily decide to store a different > person in > > my name any more than you can arbitrarily decide to store a different > value in > > x. This means that code that might look like the following C code is > invalid > > (and has no counterpart) in Haskell: > > > > int x = 5; > > [/quote] > > > > So is fair to say that an expression in Haskell like: > > > > x = 5 > > > > is more like a constant in imperative languages - say Perl? E.g. > > > > use constant SECONDS_PER_DAY => 86400; > > -- > > duke > > Thanks to all the responders!! > > --Thomas F. > > > You will get the idea in a couple of days. I am sure. > > Maybe next week! I'm going fly-fishing for trout on the weekend, as is my > usual > practice here in the Alberta (Canada) foothills ;) > > -- Kyle M. & Thomas D. > > What I gather from your replies is that the only "true" variables in > Haskell are the args passed to a function. Is that correct? > > ...and further, that what sometimes appears to be a variable to an > "unwashed" imperative programmer", is really a function with no arguments, > returning a "constant" value. How did I do? > -- > duke > You got it. It's one of the hardest things to wrap your head around (well, that and Monads) but once you do the language starts to make a whole lot more sense. I can't claim I'm a master of it or anything as I'm pretty new to the language myself but it helps explain why what another commenter on this list tried to do didn't work. He was attempting to keep track of the number of calls to a function by doing: a = a + 1which once you realize a is a function and not a variable the stack overflow he was receiving makes sense as he created an infinitely recursive function (which incidentally isn't a problem until you attempt to evaluate it which he did on the very next line when he tried to print it). Haskell can support something like a variable outside of functions using these weird little monads like MVars and IORefs (among others), but those are manipulated as something like blackboxes using various functions to store and retrieve values out of them and to understand how they work you need to understand how Monads work (something I'm not entirely clear on myself). -Kyle Murphy -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090725/a992b185/attachment-0001.html ------------------------------ Message: 4 Date: Sat, 25 Jul 2009 07:42:04 -0600 (MDT) From: Duke Normandin <dukeofp...@ml1.net> Subject: [Haskell-beginners] Sidebar to variables To: Haskell Beginners <Beginners@haskell.org> Message-ID: <alpine.osx.2.00.0907250729080....@q75-154-124-54.noufvn.gryhf.arg> Content-Type: TEXT/PLAIN; charset=US-ASCII My recent questions concerning "variables" spawned this observation: I take it that programming a solution using a functional language like Haskell is really about "linking" a series of functions from which a solution is derived. It seems to me that this approach would naturally encourage the use of the "bottom-up" method of program development. I mean, breaking the task down to the smallest possible segments, and then writing a function for each segment. Refactoring the task until the smallest segments are achieved. Very much like what I learned about programming in Forth (they use the term "words" to mean "function") Am I on the right track here, in my view of the "Haskell approach" to programming solutions? -- duke ------------------------------ Message: 5 Date: Sat, 25 Jul 2009 10:50:01 -0400 From: Thomas Friedrich <i...@suud.de> Subject: Re: [Haskell-beginners] Count how often a menu has been selected To: beginners@haskell.org Message-ID: <4a6b1b99.4090...@suud.de> Content-Type: text/plain; charset=ISO-8859-1 Bernhard Lehnert wrote: > Hi list, > > using gtk2hs I would like to count how often a Menu has been selected > (well, not really, but it kind of breaks down to this): > > > let a = 0 > onActivateLeaf menuAddOne $ do > let a = a+1 > print a > > > This leads to a stack overflow. Obviously a=a+1 is iterated over and > over again. But how can I add something each time the menu is activated? > (Actually I want to open a FileDialog and add the contents of a file to > a list but for now, counting would be great). > > Thanks to everyone for reading, > Bernhard > > > I would suggest having a look at Control.Concurrent.MVar http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent-MVar.html Best, Thomas ------------------------------ Message: 6 Date: Sat, 25 Jul 2009 18:21:20 +0200 From: Thomas Davie <tom.da...@gmail.com> Subject: Re: [Haskell-beginners] Sidebar to variables To: Duke Normandin <dukeofp...@ml1.net> Cc: Haskell Beginners <Beginners@haskell.org> Message-ID: <5803cf08-d8ab-4389-877a-36d26b87d...@gmail.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes On 25 Jul 2009, at 15:42, Duke Normandin wrote: > My recent questions concerning "variables" spawned this observation: > > I take it that programming a solution using a functional language like > Haskell is really about "linking" a series of functions from which a > solution is derived. > > It seems to me that this approach would naturally encourage the use of > the "bottom-up" method of program development. I mean, breaking the > task down to the smallest possible segments, and then writing a > function > for each segment. Refactoring the task until the smallest segments are > achieved. Very much like what I learned about programming in Forth > (they > use the term "words" to mean "function") > > Am I on the right track here, in my view of the "Haskell approach" to > programming solutions? I'm not sure -- bottom up is certainly something useful, but top down can still be done. I often write programs like this: bigFunction :: a -> b -> c bigFunction = undefined <thinks> bigFunction x = smallerFunction . otherFunction x . anotherFunction smallerFunction :: a -> b smallerFunction = undefined otherFunction :: a -> b -> c otherFunction = undefined anotherFunction :: a -> b anotherFunction = undefined <thinks> (repeat the process until no more undefineds) Bob ------------------------------ Message: 7 Date: Sat, 25 Jul 2009 13:30:36 -0300 From: Felipe Lessa <felipe.le...@gmail.com> Subject: Re: [Haskell-beginners] Count how often a menu has been selected To: beginners@haskell.org Message-ID: <20090725163036.gb24...@kira.casa> Content-Type: text/plain; charset=us-ascii On Sat, Jul 25, 2009 at 10:50:01AM -0400, Thomas Friedrich wrote: > I would suggest having a look at Control.Concurrent.MVar Probably he doesn't need MVar here because Gtk+ guarantees that all GUI code is executed on one thread, allowing you to avoid the overhead of an MVar. -- Felipe. ------------------------------ Message: 8 Date: Sat, 25 Jul 2009 20:22:33 +0200 From: Bernhard Lehnert <b.lehn...@gmx.de> Subject: [Haskell-beginners] Re: Count how often a menu has been selected To: beginners@haskell.org Message-ID: <1248546153.29584.18.ca...@sol> Content-Type: text/plain Felipe wrote: > If you want variables in the impure sense, use IORefs. > > import Data.IORef > > ... > > a <- newIORef 0 > onActivateLeaf menuAddOne $ do > modifyIORef a (+1) > print a > Hi Felipe, this works great except for the "print a" part which I replaced by: b <- readIORef a print b I should now have the tools to try to implement my real life problem. Thank you, Bernhard ------------------------------ Message: 9 Date: Sat, 25 Jul 2009 13:07:04 -0600 (MDT) From: Duke Normandin <dukeofp...@ml1.net> Subject: Re: [Haskell-beginners] Sidebar to variables To: Haskell Beginners <Beginners@haskell.org> Message-ID: <alpine.osx.2.00.0907251304310....@q75-154-116-188.noufvn.gryhf.arg> Content-Type: TEXT/PLAIN; charset=US-ASCII On Sat, 25 Jul 2009, Thomas Davie wrote: > > On 25 Jul 2009, at 15:42, Duke Normandin wrote: > > > My recent questions concerning "variables" spawned this observation: > > > > I take it that programming a solution using a functional language like > > Haskell is really about "linking" a series of functions from which a > > solution is derived. > > > > It seems to me that this approach would naturally encourage the use of > > the "bottom-up" method of program development. I mean, breaking the > > task down to the smallest possible segments, and then writing a function > > for each segment. Refactoring the task until the smallest segments are > > achieved. Very much like what I learned about programming in Forth (they > > use the term "words" to mean "function") > > > > Am I on the right track here, in my view of the "Haskell approach" to > > programming solutions? > > I'm not sure -- bottom up is certainly something useful, but top down can > still be done. I often write programs like this: > > bigFunction :: a -> b -> c > bigFunction = undefined > > <thinks> > > bigFunction x = smallerFunction . otherFunction x . anotherFunction > > smallerFunction :: a -> b > smallerFunction = undefined > > otherFunction :: a -> b -> c > otherFunction = undefined > > anotherFunction :: a -> b > anotherFunction = undefined > > <thinks> > > (repeat the process until no more undefineds) > > Bob Hey Bob.... I think you are describing what is usually referred to as refactoring. ;) -- duke ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 13, Issue 16 *****************************************