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: Simple Chess Program for Learning FP (Daniel Fischer) 2. Re: Simple Chess Program for Learning FP (Heinrich Apfelmus) 3. Re: Simple Chess Program for Learning FP (Christian Maeder) 4. Re: Simple Chess Program for Learning FP (Yitzchak Gale) 5. Re: lazy IO in readFile (Chadda? Fouch?) ---------------------------------------------------------------------- Message: 1 Date: Tue, 1 Jun 2010 23:28:20 +0200 From: Daniel Fischer <daniel.is.fisc...@web.de> Subject: Re: [Haskell-beginners] Simple Chess Program for Learning FP To: beginners@haskell.org Message-ID: <201006012328.20565.daniel.is.fisc...@web.de> Content-Type: text/plain; charset="iso-8859-1" On Tuesday 01 June 2010 22:54:38, Jordan Cooper wrote: > Thank you, Daniel and Yitzchak! I think that will be enough to get me > started. As a general question, at what number of elements does it > become impractical to use Lists? That utterly depends on what you're doing and how important performance is. If performance is *very* important, you can write faster code already to replace very short lists. That code will be far far longer and far far uglier than list-using code, though. We have a great number of very nice functions for manipulating lists, that makes writing list-using code nice easy and fast. If you use other data structures (where lists are a natural choice), the code and coding tends to be less pleasant. And most of the time, not so very much faster. Haskell implementations (well, certainly GHC and hugs, haven't tried others much) are pretty good with lists. If you consume your lists in the order they are produced, lists of several million elements can have nice performance. If your use-pattern isn't so good, lists of a few hundred elements can give really stinking performance. If your code contains many (!!), you are doing something wrong. If your code contains "length list == 0" (or "== 1", "== 2"), you are doing something horribly wrong. ------------------------------ Message: 2 Date: Wed, 02 Jun 2010 09:42:50 +0200 From: Heinrich Apfelmus <apfel...@quantentunnel.de> Subject: [Haskell-beginners] Re: Simple Chess Program for Learning FP To: beginners@haskell.org Message-ID: <hu521r$ug...@dough.gmane.org> Content-Type: text/plain; charset=UTF-8 Yitzchak Gale wrote: > > A chess board is only 8x8, so depending on your algorithms, > a simple 2 dimensional list might be the fastest: > > [[Maybe Piece]] > > That also allows you to write simple, beautiful functional code, using > the wide selection of list functions available in the Prelude > and Data.List. > > If you choose a map from positions to pieces, it might turn out > to be just about as fast to use a simple association list > > [(Int, Int), Maybe Piece] > > instead of all the machinery of Data.Map.Map (Int, Int) (Maybe Piece) > A chess board has only 64 locations. Ironically, it appears to me that Data.Map is *easier* to use than an association list [(a,b)] , mainly because there aren't many functions in the Prelude for working with association lists. Regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com ------------------------------ Message: 3 Date: Wed, 02 Jun 2010 13:07:48 +0200 From: Christian Maeder <christian.mae...@dfki.de> Subject: [Haskell-beginners] Re: Simple Chess Program for Learning FP To: nefi...@gmail.com Cc: beginners@haskell.org Message-ID: <4c063b84.2020...@dfki.de> Content-Type: text/plain; charset=ISO-8859-1 Yitzchak Gale schrieb: [...] > If you choose a map from positions to pieces, it might turn out > to be just about as fast to use a simple association list > > [(Int, Int), Maybe Piece] > > instead of all the machinery of Data.Map.Map (Int, Int) (Maybe Piece) > A chess board has only 64 locations. if you associate positions to pieces, you can omit "Maybe" and simple delete positions without pieces from the Map. So your Map will only have 32 entries or fewer. Furthermore, you could code your row and column positions (r, c) as a single Int p and use Data.IntMap.IntMap Piece. p = 8 * r + c c = mod p 8 r = div p 8 Have fun Christian ------------------------------ Message: 4 Date: Wed, 2 Jun 2010 14:21:34 +0300 From: Yitzchak Gale <g...@sefer.org> Subject: [Haskell-beginners] Re: Simple Chess Program for Learning FP To: Christian Maeder <christian.mae...@dfki.de> Cc: beginners@haskell.org Message-ID: <aanlktimmavypmzvqx-cqzck1arcuhw3j8peioqwrt...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 > if you associate positions to pieces, you can omit "Maybe" and simple > delete positions without pieces from the Map. So your Map will only have > 32 entries or fewer. Yep, good point. The same is true for Data.Map, too. > Furthermore, you could code your row and column positions (r, c) as a > single Int p and use Data.IntMap.IntMap Piece. Also true. I think that would really be overkill for a chessboard, though. Unless perhaps you're trying to build "Big Blue" in Haskell. Regards, Yitz ------------------------------ Message: 5 Date: Wed, 2 Jun 2010 18:40:15 +0200 From: Chadda? Fouch? <chaddai.fou...@gmail.com> Subject: Re: [Haskell-beginners] lazy IO in readFile To: Andrew Sackville-West <and...@swclan.homelinux.org> Cc: beginners@haskell.org Message-ID: <aanlktilgtafb2-iw5niio2umnehzd3-uvf_yopyh2...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Thu, May 20, 2010 at 3:17 AM, Andrew Sackville-West <and...@swclan.homelinux.org> wrote: > thanks for this. it helps a lot. hmmm... I wonder why it is I never > have a problem returning functions in Scheme, but it never occurs to > me as I learn Haskell? Maybe you're already doing it without realizing it ? For instance for the same kind of problem but without the IO part, the type of the function could be : > getIsNewItemPredicate :: stuff -> (String -> Bool) but in normal Haskell, you wouldn't write this last pair of parenthesis (since they're implicit) : > getIsNewItemPredicate :: stuff -> String -> Bool And so it is pretty likely that you would write this function just as if it had two parameters : > getIsNewItemPredicate stuff str = .... str `isMember` set And later on use the fact that the function is curried to get a predicate on String : > let isNewItem = getIsNewItemPredicate someStuff In this case, you're "returning" a function but it may not be as obvious as in Scheme (where curryfication is not an idiom encouraged by the language). -- Jedaï ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 24, Issue 3 ****************************************