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. find problem (Roelof Wobben) 2. Re: find problem (aditya siram) 3. Re: problem exercise 3 page 60 Programming in Haskell (David Place) 4. Re: very impure [global] counter (Thomas) 5. Re: very impure [global] counter (Davi Santos) 6. a problem with maps (Dennis Raddle) 7. Re: a problem with maps (Dennis Raddle) 8. Re: a problem with maps (David Place) ---------------------------------------------------------------------- Message: 1 Date: Fri, 22 Jul 2011 19:14:53 +0000 From: Roelof Wobben <rwob...@hotmail.com> Subject: [Haskell-beginners] find problem To: <beginners@haskell.org> Message-ID: <snt118-w38c0683e5bbc527cecaf61ae...@phx.gbl> Content-Type: text/plain; charset="iso-8859-1" Hello, Sorry for asking so much but I really want to understand this. I have the function find k t [v, (k',v') <- t,k = v] Let's say k = false and t = [false, true, false, true] Then It will be find "false" ["false", "true", "false", "true] But where on earth are t,k = v and (k', v') come from ? Roelof -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20110722/a6c7d4d3/attachment-0001.htm> ------------------------------ Message: 2 Date: Fri, 22 Jul 2011 15:06:06 -0500 From: aditya siram <aditya.si...@gmail.com> Subject: Re: [Haskell-beginners] find problem To: Roelof Wobben <rwob...@hotmail.com> Cc: beginners@haskell.org Message-ID: <cajrreygyop73tjw3jru3pu8f3ax4yu4endv+ar1nzh6kc8w...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Hi Roelof, The function itself will not work. Do you have a working Haskell environment? If so, please try the function out first and let us know what errors you see. I have a feeling from this and previous questions that you're trying to understand the code just by trying to reading it. You really need to execute it. Since you're posting here I presume you have access to a computer, or at least the Web. Have you used http://tryhaskell.org/? That said I'll try and guess what "find" is supposed to do. It seems to take a key "k" and output the values associated with the key. It also appears that "t" is a list of key-value pairs eg. [("a", "aardvard"), ("a", "armadillo"), ("b", bull")]. From your definition of "find" it is different from a standard lookup table in that it will will return all values associated with a key instead of just the first. Eg. find "a" [("a", "aardvark"), ("a", "armadillo"), ("b", bull")] == ["aardvark", "armadillo"]. This definition of "find": find :: (Eq a) => a -> [(a,b)] -> [b] find k t = [v' | (k', v') <- t , k == k'] seems to be what you want. Firstly you're chunking the list comprehension incorrectly, the above is the same as: find k t = [v' | (k',v') <- t, k == k'] The first part of the comprehension "(k',v') <- t" gets a tuple out of the list and assigns first part to "k'" and the second to "v'". The second part "k == k'" places a constraint on the list so that only tuples whose first element is equal to the key passed in "k" are allowed. The result of the comprehension, the v' before the "|" character indicates that the second element of the tuple should be output. Taking the above definition try to trace by hand the execution of "find". It'll give you a better idea of how result is generated. -deech On Fri, Jul 22, 2011 at 2:14 PM, Roelof Wobben <rwob...@hotmail.com> wrote: > Hello, > > Sorry for asking so much but I really want to understand this. > > I have the function find? k t [v, (k',v') <- t,k = v] > > Let's say k = false and t = [false, true, false, true] > > Then It will be? find? "false" ["false", "true", "false", "true] > But where on earth are t,k = v and (k', v') come from ? > > Roelof > > > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > ------------------------------ Message: 3 Date: Fri, 22 Jul 2011 16:11:59 -0400 From: David Place <d...@vidplace.com> Subject: Re: [Haskell-beginners] problem exercise 3 page 60 Programming in Haskell To: Roelof Wobben <rwob...@hotmail.com> Cc: beginners@haskell.org Message-ID: <3363e864-d1a5-4267-81a2-d3f287350...@vidplace.com> Content-Type: text/plain; charset="iso-8859-1" On Jul 22, 2011, at 2:29 PM, Roelof Wobben wrote: > But the exercise says you have to use one generator and I see still two. You misunderstand the exercise. It says to restate the list comprehension as two comprehensions each with a single generator. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20110722/a577824b/attachment-0001.htm> ------------------------------ Message: 4 Date: Sat, 23 Jul 2011 01:50:43 +0200 From: Thomas <hask...@phirho.com> Subject: Re: [Haskell-beginners] very impure [global] counter To: beginners@haskell.org Message-ID: <4e2a0cd3.90...@phirho.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hello David, since your first approach was via the filesystem I assume you only need to call a more or less limited number of methods in Java. If this is the case then I would try to embed Java into C and call C from Haskell via the FFI. I have done both individually, it's not hard and it worked pretty well. I'm not sure if there are any lurking problems when "double embedding". But even if that should fail: before using the filesystem as communication mechanism I'd probably use some sort of IPC (probably network). If you really want a virtual filesystem for the communication, you can always set one up in your host OS: http://www.vanemery.com/Linux/Ramdisk/ramdisk.html Or search the web for "ramdisk <os of choice>" if you're not using Linux. I don't think Haskell provides this functionality as a library. I may be wrong, though. HTH, Thomas On 22.07.2011 19:23, Davi Santos wrote: > Aditya, > as I could search, If there is a C version of Weka, it appears to be very > outdated by now. > The library I use is http://www.cs.waikato.ac.nz/ml/weka/. > > Davi > > > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners ------------------------------ Message: 5 Date: Fri, 22 Jul 2011 21:42:58 -0300 From: Davi Santos <dps....@gmail.com> Subject: Re: [Haskell-beginners] very impure [global] counter To: Thomas <hask...@phirho.com> Cc: beginners@haskell.org Message-ID: <CANWsST_i2JyLs5Bq=bo9kfjxpupmr1pov90boz3n0eo709a...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" Thomas, the Weka Java library has a myriad of methods I want to call. To be clear, actually, it comes in three flavours: library, GUI and program. Unfortunately, as a library, it is unfeasible to map all of them to C or to a message passing system. When used as a program (such as I've done in Haskell), it arranges the methods in a way I can do almost everything just via command line options. The downside is that data can be exchanged only by files. So, I manipulate data in Haskell and send it ready to a file every time I need Weka to be called. Thousand times, BTW. Anyway, the perfect and impossible world would be to instantiate java classes directly in Haskell and use all Weka features. In time: when I run the program, I create a ramdisk this way: sudo mount -t tmpfs -o size=1024M tmpfs /tmp/ram/ it works, but makes the program to depend on external settings. May be I should do that via a Haskell system call also. I was hoping somebody would point out a secret Jaskell-like solution. :) Ah, to make myself even clearer, all of this is to avoid programming in Java, or better, to avoid hunting bugs all day in my own code. Davi[d] [the names are the same by here, no problem T. Holubar!] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20110722/be43f1b5/attachment-0001.htm> ------------------------------ Message: 6 Date: Fri, 22 Jul 2011 18:40:20 -0700 From: Dennis Raddle <dennis.rad...@gmail.com> Subject: [Haskell-beginners] a problem with maps To: Beginners@haskell.org Message-ID: <cakxlvopl3xjbv_nps2m8nh-3nuhpojanxxkxi2u1uysycoz...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" In my application I find an issue coming up frequently. I have a map Ord k => Map k [a] That is, a list of things may be stored at each key. I sometimes want to convert it to [(k,a)] where each value is paired with its key, and some keys may repeat in that form of the list. No particular order is needed. so I have the following code. Would appreciate hearing if there are any tricks I'm missing import qualified Map as M listOutMap :: Ord k => Map k [a] -> [(k,a)] listOutMap m = concatMap (\(k,a) -> zip (repeat k) a) (M.toList m) mapOutList :: Ord k => [(k,a)] -> Mpa k [a] mapOutList list = M.fromList $ map (second (: [])) list -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20110722/34d41627/attachment-0001.htm> ------------------------------ Message: 7 Date: Fri, 22 Jul 2011 18:41:57 -0700 From: Dennis Raddle <dennis.rad...@gmail.com> Subject: Re: [Haskell-beginners] a problem with maps To: Beginners@haskell.org Message-ID: <cakxlvoqqwhonsy6wv1o+ezjvsn2bta7wxbwdturqhucqcw5...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" Oops that was supposed to be mapOutList list = M.fromListWith (++) $ map (second (: [])) list On Fri, Jul 22, 2011 at 6:40 PM, Dennis Raddle <dennis.rad...@gmail.com>wrote: > In my application I find an issue coming up frequently. I have a map > > Ord k => Map k [a] > > That is, a list of things may be stored at each key. I sometimes want to > convert it to > > [(k,a)] > > where each value is paired with its key, and some keys may repeat in that > form of the list. No particular order is needed. > > so I have the following code. Would appreciate hearing if there are any > tricks I'm missing > > import qualified Map as M > > listOutMap :: Ord k => Map k [a] -> [(k,a)] > listOutMap m = concatMap (\(k,a) -> zip (repeat k) a) (M.toList m) > > mapOutList :: Ord k => [(k,a)] -> Mpa k [a] > mapOutList list = M.fromList $ map (second (: [])) list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20110722/2d1b972b/attachment-0001.htm> ------------------------------ Message: 8 Date: Fri, 22 Jul 2011 21:54:10 -0400 From: David Place <d...@vidplace.com> Subject: Re: [Haskell-beginners] a problem with maps To: Dennis Raddle <dennis.rad...@gmail.com> Cc: Beginners@haskell.org Message-ID: <7548a985-5449-44bc-b6a3-b850c4bc7...@vidplace.com> Content-Type: text/plain; charset="iso-8859-1" On Jul 22, 2011, at 9:41 PM, Dennis Raddle wrote: > mapOutList list = M.fromListWith (++) $ map (second (: [])) list > Is `second` the function from Control.Arrow? ____________________ David Place Owner, Panpipes Ho! LLC http://panpipesho.com d...@vidplace.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20110722/50bb2ad1/attachment.htm> ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 37, Issue 48 *****************************************