Send Beginners mailing list submissions to
[email protected]
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
[email protected]
You can reach the person managing the list at
[email protected]
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 <[email protected]>
Subject: Re: [Haskell-beginners] Simple Chess Program for Learning FP
To: [email protected]
Message-ID: <[email protected]>
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 <[email protected]>
Subject: [Haskell-beginners] Re: Simple Chess Program for Learning FP
To: [email protected]
Message-ID: <[email protected]>
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 <[email protected]>
Subject: [Haskell-beginners] Re: Simple Chess Program for Learning FP
To: [email protected]
Cc: [email protected]
Message-ID: <[email protected]>
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 <[email protected]>
Subject: [Haskell-beginners] Re: Simple Chess Program for Learning FP
To: Christian Maeder <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
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? <[email protected]>
Subject: Re: [Haskell-beginners] lazy IO in readFile
To: Andrew Sackville-West <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Thu, May 20, 2010 at 3:17 AM, Andrew Sackville-West
<[email protected]> 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
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 24, Issue 3
****************************************