Re: [Haskell-cafe] [Newbie] Problem with Data.Map (or something else ?)

2008-03-31 Thread Don Stewart
chaddai.fouche:
> 2008/3/31, Bruno Carnazzi <[EMAIL PROTECTED]>:
> >Dears Haskellers,
> >
> >  As an Haskell newbie, I'm learning Haskell by trying to resolve Euler
> >  Project problems (http://projecteuler.net/ ). I'm hanging on problem
> >  14 (Collatz problem).
> >
> >  I've written the following program... Which does not end in a reasonable 
> > time :(
> >  My algorithm seems ok to me but I see that memory consumption is 
> > gigantic...
> >  Is this a memory problem with Data.Map ? Or an infinite loop ? (Where ?)
> >  In a more general way, how can I troubleshoot these kind of problem ?
> 
> Others have pointed potential source of memory leaks, but I must say
> that using Data.Map for the cache in the first place appear to me as a
> very bad idea... Data.Map by nature take much more place than
> necessary. You have an integer index, why not use an array instead ?
> 
> > import Data.Array
> > import Data.List
> > import Data.Ord
> >
> > syrs n = a
> > where a = listArray (1,n) $ 0:[ syr n x | x <- [2..n]]
> >   syr n x = if x' <= n then a ! x' else 1 + syr n x'
> >   where x' = if even x then x `div` 2 else 3 * x + 1
> >
> > main = print $ maximumBy (comparing snd) $ assocs $ syrs 100
> 
> This solution takes 2 seconds (on my machine) to resolve the problem.
> 
> On the other hand, now that I have read your solution, I see that
> using Map was the least of the problem... All those Map.map, while
> retaining the original Map... Your solution is too clever (twisted)
> for its own good, I suggest you aim for simplicity next time.
> 

and if its got Int indices, Data.IntMap is always a better option than Data.Map
and usually outperforms the HashTable type, while being pure.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [Newbie] Problem with Data.Map (or something else ?)

2008-03-31 Thread Chaddaï Fouché
2008/3/31, Bruno Carnazzi <[EMAIL PROTECTED]>:
>Dears Haskellers,
>
>  As an Haskell newbie, I'm learning Haskell by trying to resolve Euler
>  Project problems (http://projecteuler.net/ ). I'm hanging on problem
>  14 (Collatz problem).
>
>  I've written the following program... Which does not end in a reasonable 
> time :(
>  My algorithm seems ok to me but I see that memory consumption is gigantic...
>  Is this a memory problem with Data.Map ? Or an infinite loop ? (Where ?)
>  In a more general way, how can I troubleshoot these kind of problem ?

Others have pointed potential source of memory leaks, but I must say
that using Data.Map for the cache in the first place appear to me as a
very bad idea... Data.Map by nature take much more place than
necessary. You have an integer index, why not use an array instead ?

> import Data.Array
> import Data.List
> import Data.Ord
>
> syrs n = a
> where a = listArray (1,n) $ 0:[ syr n x | x <- [2..n]]
>   syr n x = if x' <= n then a ! x' else 1 + syr n x'
>   where x' = if even x then x `div` 2 else 3 * x + 1
>
> main = print $ maximumBy (comparing snd) $ assocs $ syrs 100

This solution takes 2 seconds (on my machine) to resolve the problem.

On the other hand, now that I have read your solution, I see that
using Map was the least of the problem... All those Map.map, while
retaining the original Map... Your solution is too clever (twisted)
for its own good, I suggest you aim for simplicity next time.

-- 
Jedaï
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] HDBC, character encoding

2008-03-31 Thread Peter Gammie

On 31/03/2008, at 11:42 PM, Bjorn Bringert wrote:


2008/3/26 Adrian Neumann <[EMAIL PROTECTED]>:

Hi,

I wrote a CGI program to access a Postgres database using HDBC. [...]


I think that Peter Gammie (copied) has some code to deal with this.


I added some stuff to HSQL (not HDBC) and HaskellDB so that UTF8 can  
be used to talk to the database. It's not very pretty though, so I  
haven't tried to get it merged.


cheers
peter
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How can I represent 4x4 map in haskell

2008-03-31 Thread iliali16

I mean board but I found the solution to my problem don't worry I really
don't want someone to do my Project since I won't learn from that and I
really want to learn since that's what is important at the end of the day.
Thanks to all that people who understood what I mean and advised me, thanks
again! 


Chris Smith wrote:
> 
> iliali16 wrote:
> 
>> Hi can you please tell me how can I represent 4x4 map in haskell.Should
>> I show it as a list of lines and each line to be  a list of char or I am
>> mistaken? Thanks in advance!
> 
> What do you mean by a 4x4 map?  Maybe I'm missing something obvious, but 
> there are several different meanings for "map", and I don't see which one 
> you mean.
> 
> -- 
> Chris Smith
> 
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-can-I-represent-4x4-map-in-haskell-tp16396273p16401807.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [GSoC] Student applications deadline extended one week

2008-03-31 Thread Adam Langley
On Mon, Mar 31, 2008 at 12:00 PM, Manlio Perillo
<[EMAIL PROTECTED]> wrote:
>  Since Nginx is asynchronous, how can be solved the producer-consumer
>  problem (that is, the Haskell program produces more data that Nginx can
>  send to the client without blocking)?

I assume that the Haskell process is connected to nginx over a pipe or
socket. In which case, nginx can use flow control to block the sending
side of the pipe and the Haskell code will backup on that.

If many connections need to be multiplexed over the same
flow-controlled entity (i.e. a pipe), without head-of-line blocking
then you can just suspend the current thread using an MVar or the STM
objects.

Alternatively, with Network.MiniHTTP the problem is turned inside out.
Request handlers give return a Source object, which can be asked to
generate more data on request. This would be similar to generators in
Python.


AGL

-- 
Adam Langley [EMAIL PROTECTED] http://www.imperialviolet.org
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [Newbie] Problem with Data.Map (or something else ?)

2008-03-31 Thread Luke Palmer
On Mon, Mar 31, 2008 at 6:00 PM, Bruno Carnazzi <[EMAIL PROTECTED]> wrote:
> I've done this modification with no more success :
>
>  import qualified Data.List as List
>  import qualified Data.Map as Map
>
>  f :: Integer -> Integer
>
> f n | even n = n `div` 2
> | otherwise = 3 * n + 1
>
>  chain m n =
> let chain' cn cm | Map.member cn m = Map.map (+ (m Map.! cn)) cm
>  | otherwise = chain' (f cn) $! Map.insert cn 1 (Map.map 
> (+1) cm)
> in chain' n Map.empty

This function raises a red flag for me.  The collatz sequence gets
_very_ big, with
very many distinct numbers.  You are saving the length of the
resulting chain for
each of those numbers, which is going to take a lot of memory.  But
Map is also lazy
in its values, so the values you are storing once chain finishes will look like:

   1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1

Instead of 22, which is taking quite a lot of memory as well.

My impression is that the caching approach is just a bad idea.  It is
not necessary
to solve the problem efficiently; a brute force approach runs in under
1 minute in
constant memory for me.

Try to simplify your approach.  I'd suggest generating a list
representing the collatz
sequence starting at the number, then just taking its 'length'.  Do
that for each number
and find the maximum.  There should be no need for Data.Map.

Luke
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [GSoC] X Haskell bindings

2008-03-31 Thread Donnie Jones
Hello Antoine,

On Mon, Mar 31, 2008 at 3:23 PM, Antoine Latter <[EMAIL PROTECTED]> wrote:

> I've been looking into to this a bit myself, and have had trouble with
> the fact that the XML descriptions of the protocol are extremely
> C-centric.  As in, the union types defined in the XML are C-unions,
> and I've seen a struct definition which uses padding-bytes to store
> semantically useful data.
>
> Both of which are fine things to do in C, but a bit tricky to map onto
> Haskell.
>

Maybe this Haskell package libxml [1] will be helpful for this.  The package
provides bindings for the XML parser and toolkit for Gnome: libxml [2].

Hope this helps.
__
Donnie

1. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/libxml-0.1
2. http://xmlsoft.org/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [GSoC] X Haskell bindings

2008-03-31 Thread Antoine Latter
I've been looking into to this a bit myself, and have had trouble with
the fact that the XML descriptions of the protocol are extremely
C-centric.  As in, the union types defined in the XML are C-unions,
and I've seen a struct definition which uses padding-bytes to store
semantically useful data.

Both of which are fine things to do in C, but a bit tricky to map onto Haskell.

You should still be able to generate a large amount of data-types and
serializing/deserializing code automatically.

As for code generation, Language.Haskell.Syntax paired with
Language.Haskell.Pretty is a pretty good way to do it, from what I can
tell.




On Mon, Mar 31, 2008 at 1:29 PM, Adam Langley <[EMAIL PROTECTED]> wrote:
> 2008/3/31 Roman Cheplyaka <[EMAIL PROTECTED]>:
>
> >  Especially I need help with "Milestones" section. I'm not quite sure how
>  >  it should look like for such project.
>
>  This would seem to be a commendable SoC project. I'm not sure that the
>  milestones are all that important - no plan ever survives contact with
>  reality. However, I'd suggest that these would be important aspects:
>
>  * A working parser for the XCB (this involves choosing an XML parser
>  and getting useful data structures from it)
>  * A working Haskell code generator which outputs bindings for a
>  minimal subset of the functions
>
>  (the last two need not be in Haskell, although I suspect that it would
>  be a good idea for them to be so)
>
>  * The first, minimal, Haskell X client using XCB
>  * Having sensible bindings for 25%/50%/75% and 100% of the XCB interface.
>
>
>
>  AGL
>
>  --
>  Adam Langley [EMAIL PROTECTED] http://www.imperialviolet.org
>  ___
>  Haskell-Cafe mailing list
>  Haskell-Cafe@haskell.org
>  http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [GSoC] X Haskell bindings

2008-03-31 Thread Roman Cheplyaka
* Adam Langley <[EMAIL PROTECTED]> [2008-03-31 11:29:57-0700]
> 2008/3/31 Roman Cheplyaka <[EMAIL PROTECTED]>:
> >  Especially I need help with "Milestones" section. I'm not quite sure how
> >  it should look like for such project.
> 
> This would seem to be a commendable SoC project. I'm not sure that the
> milestones are all that important - no plan ever survives contact with
> reality. However, I'd suggest that these would be important aspects:
> 
> * A working parser for the XCB (this involves choosing an XML parser
> and getting useful data structures from it)
> * A working Haskell code generator which outputs bindings for a
> minimal subset of the functions
> 
> (the last two need not be in Haskell, although I suspect that it would
> be a good idea for them to be so)
> 
> * The first, minimal, Haskell X client using XCB
> * Having sensible bindings for 25%/50%/75% and 100% of the XCB interface.

Thanks, Adam!
Your suggestions will help me a lot.

-- 
Roman I. Cheplyaka :: http://ro-che.info/
...being in love is totally punk rock...


signature.asc
Description: Digital signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [GSoC] Student applications deadline extended one week

2008-03-31 Thread Manlio Perillo

Don Stewart ha scritto:

Hey all,

As you might know, the Google Summer of Code application submission
period is open. Google has decided to extend the deadline for initial
student applications by one week,


http://groups.google.com/group/google-summer-of-code-announce/browse_thread/thread/9fa88f31aa401f70

If you've thought about submitting, and are interested in hacking on
Haskell for 3 months this summer, and bootstrapping into the Haskell
developer community, check our project wiki,

http://hackage.haskell.org/trac/summer-of-code/wiki/SoC2008

and get your applications into google this week!

-- Don




Hi.
I'm very new to Haskell.


From the SoC2008 page I see that there is a project for working on a 
mod_haskell for Apache.


Now, I'm the author of the WSGI (Python Web Server gateway Interface) 
module for Nginx:


http://hg.mperillo.ath.cx/nginx/mod_wsgi/


I'm thinking about writing an Haskell module for Nginx, for learning 
purpose.


I'm not a student, so this is not a SoC2008 proposal, but I'm very 
interested in related works.



As an example, how should be a CGI like interface for Haskell?


Since Nginx is asynchronous, how can be solved the producer-consumer 
problem (that is, the Haskell program produces more data that Nginx can 
send to the client without blocking)?


I have easily solved this in Python, since the WSGI application returns 
a generator and I can simply suspend the iteration.



Is it possible to support asynchronous Haskell applications (as an 
example an application that needs to do a HTTP request to a server 
without blocking the worker process)?


Here, again, I have solved the problem for Python by making use of 
generators:

http://hg.mperillo.ath.cx/nginx/mod_wsgi/file/tip/examples/nginx-postgres-async.py

(but this is very experimental)




Thanks and sorry for having used this thread for an unrelated topic
(I have removed the Cc to haskell-soc-2008)



Manlio Perillo
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [GSoC] X Haskell bindings

2008-03-31 Thread Adam Langley
2008/3/31 Roman Cheplyaka <[EMAIL PROTECTED]>:
>  Especially I need help with "Milestones" section. I'm not quite sure how
>  it should look like for such project.

This would seem to be a commendable SoC project. I'm not sure that the
milestones are all that important - no plan ever survives contact with
reality. However, I'd suggest that these would be important aspects:

* A working parser for the XCB (this involves choosing an XML parser
and getting useful data structures from it)
* A working Haskell code generator which outputs bindings for a
minimal subset of the functions

(the last two need not be in Haskell, although I suspect that it would
be a good idea for them to be so)

* The first, minimal, Haskell X client using XCB
* Having sensible bindings for 25%/50%/75% and 100% of the XCB interface.



AGL

-- 
Adam Langley [EMAIL PROTECTED] http://www.imperialviolet.org
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [Newbie] Problem with Data.Map (or something else ?)

2008-03-31 Thread Bruno Carnazzi
I've done this modification with no more success :

import qualified Data.List as List
import qualified Data.Map as Map

f :: Integer -> Integer
f n | even n = n `div` 2
| otherwise = 3 * n + 1

chain m n =
let chain' cn cm | Map.member cn m = Map.map (+ (m Map.! cn)) cm
 | otherwise = chain' (f cn) $! Map.insert cn 1
(Map.map (+1) cm)
in chain' n Map.empty

chains n = List.foldl' (\m i -> Map.union m (chain m i))
(Map.singleton 1 1) [2..n]

maxCollatz c1@(_,l1) c2@(_,l2) | l1 < l2 = c2
   | otherwise = c1

maxChain = List.foldl' maxCollatz (0,0) . Map.toList . chains

main =
let n = 100
in putStrLn $ show $ maxChain n

Best regards,

Bruno.

2008/3/31, Ketil Malde <[EMAIL PROTECTED]>:
> "Bruno Carnazzi" <[EMAIL PROTECTED]> writes:
>
>  > The program ends for values up to 40 :
>
>
> Wild guess here - I know nothing about the problem, and haven't
>  examined your program in detail - but could it be that you default to
>  Int, and that it wraps silently at some power of two, thereby making
>  your algorithm wrap around?  Try to stick some 'Integer' type
>  annotations in there, and see if it helps.
>
>  -k
>
>  (cetera censeo...)
>
> --
>  If I haven't seen further, it is by standing in the footprints of giants
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [Newbie] Problem with Data.Map (or something else ?)

2008-03-31 Thread Ketil Malde
"Bruno Carnazzi" <[EMAIL PROTECTED]> writes:

> The program ends for values up to 40 :

Wild guess here - I know nothing about the problem, and haven't
examined your program in detail - but could it be that you default to
Int, and that it wraps silently at some power of two, thereby making
your algorithm wrap around?  Try to stick some 'Integer' type
annotations in there, and see if it helps.

-k

(cetera censeo...)
-- 
If I haven't seen further, it is by standing in the footprints of giants
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] [GSoC] Student applications deadline extended one week

2008-03-31 Thread Don Stewart
Hey all,

As you might know, the Google Summer of Code application submission
period is open. Google has decided to extend the deadline for initial
student applications by one week,


http://groups.google.com/group/google-summer-of-code-announce/browse_thread/thread/9fa88f31aa401f70

If you've thought about submitting, and are interested in hacking on
Haskell for 3 months this summer, and bootstrapping into the Haskell
developer community, check our project wiki,

http://hackage.haskell.org/trac/summer-of-code/wiki/SoC2008

and get your applications into google this week!

-- Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [Newbie] Problem with Data.Map (or something else ?)

2008-03-31 Thread Bruno Carnazzi
The program ends for values up to 40 :

*Main> :set +s
*Main> maxChain 1000
(871,179)
(0.09 secs, 3697648 bytes)
*Main> maxChain 1
(6171,262)
(0.73 secs, 31560008 bytes)
*Main> maxChain 10
(77031,351)
(9.31 secs, 347122064 bytes)
*Main> maxChain 20
(156159,383)
(19.32 secs, 709303708 bytes)

<< This one take about 10 minutes and swap a lot >>
*Main> maxChain 30
(230631,443)
(38.02 secs, 1083800124 bytes)

<< This one swap a lot and does not end in less than 10 minutes >>
*Main> maxChain 40

The ratio memreq/n seems to be more or less constant :
*Main> 3697648/1000
3697.648
*Main> 31560008/1
3156.0008
*Main> 347122064/10
3471.22064
*Main> 709303708/20
3546.51854
*Main> 1083800124/30
3612.66708

Thank you,

Bruno.

2008/3/31, Bulat Ziganshin <[EMAIL PROTECTED]>:
> Hello Bruno,
>
>
>  Monday, March 31, 2008, 7:51:43 PM, you wrote:
>
>  > I've written the following program... Which does not end in a reasonable 
> time :(
>  > My algorithm seems ok to me but I see that memory consumption is 
> gigantic...
>  > Is this a memory problem with Data.Map ? Or an infinite loop ? (Where ?)
>  > In a more general way, how can I troubleshoot these kind of problem ?
>
>
> first step is to reduce n and see whether program will finish and how
>  memreqs depends on value of n
>
>  > main =
>  > let n = 100
>
>
>
>  --
>  Best regards,
>   Bulatmailto:[EMAIL PROTECTED]
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] HDBC, character encoding

2008-03-31 Thread Bjorn Bringert
2008/3/26 Adrian Neumann <[EMAIL PROTECTED]>:
> Hi,
>
>  I wrote a CGI program to access a Postgres database using HDBC. The
>  database stores books and I want to display those from a certain
>  author. Everything works fine, unless I search for someone with an
>  umlaut in his name. Böll, for example. I have a function like this
>
>   > bookByAuthor :: Connection -> AutorName -> IO [[String]]
>   > bookByAuthor c aName = do
>   >  writeFile "./err.log" ((show aName)++" "++(show $ toSql aName))
>   >  rows <- quickQuery c "SELECT * FROM buecher WHERE lower
>  (autor_name) LIKE ? ORDER BY autor_name, buch_name" [toSql $ map
>  toLower $ '%':aName++"%"]
>   >  return $ map (map fromSql) rows
>
>  It returns me a SqlError. However, doing the same in ghci works
>  perfectly. I can't understand why. err.log contains
>
>   > "b\195\182ll" SqlString "b\195\182ll"
>
>  which is ok I think. Since
>
>   > quickQuery c "SELECT * FROM buecher WHERE lower(autor_name) LIKE ?
>  ORDER BY autor_name, buch_name" [toSql "%b\195\182%"]
>
>  works in ghci. I have tried "b\246ll", but that doesn't even work in
>  ghci, although the database-encoding is utf-8. This all is really
>  annoying...

I think that Peter Gammie (copied) has some code to deal with this.

/Björn
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] [GSoC] X Haskell bindings

2008-03-31 Thread Roman Cheplyaka
Hi!

I've written a draft proposal for GSoC on XCB Haskell Bindings[1].
I'd appreciate any feedback.
Especially I need help with "Milestones" section. I'm not quite sure how
it should look like for such project.

  1. http://ro-che.info/docs/xhsb.txt
-- 
Roman I. Cheplyaka :: http://ro-che.info/
...being in love is totally punk rock...


signature.asc
Description: Digital signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Seeking Daan Leijen

2008-03-31 Thread Bjorn Bringert
On Thu, Mar 27, 2008 at 6:43 PM, John Goerzen <[EMAIL PROTECTED]> wrote:
> I tried to email this to Daan, but his mail is bouncing...
>
>  Subject: http://legacy.cs.uu.nl/daan/parsec.html
>
>  Hi Daan,
>
>  I noticed Parsec 3.0.0 on Hackage, and went to your homepage to read about
>  the new package.  But it looks like your homepage still has the old version
>  put out in 2003.  This might cause confusion for some that are looking
>  for new releases at your website.

Daan is now working at Microsoft Research, see
http://research.microsoft.com/users/daan/

/Bjorn
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: HTTP client libraries

2008-03-31 Thread John Goerzen
On 2008-03-30, Iavor Diatchki <[EMAIL PROTECTED]> wrote:
> Hi,
>
> On Fri, Mar 28, 2008 at 6:42 AM, John Goerzen <[EMAIL PROTECTED]> wrote:
>> On 2008-03-28, Don Stewart <[EMAIL PROTECTED]> wrote:
>>  > paulrbrown+haskell-cafe:
>>
>> > And we have a curl binding, already in wide use.
>>  >
>>  > http://code.haskell.org/curl.git/
>>  >
>>  > a release to hackage is imminent.
>>
>>  Do you mean this?
>>
>>  http://hackage.haskell.org/cgi-bin/hackage-scripts/package/curl-1.3.1
>>
>>  Looks like it's not quite as current as your Git repo.
>
> Is this surprising?  Hackage is not a revision control system.
> The curl package on hackage is a fairly recent version of the git repo.

No, but I was confirming that the Hackage package corresponds to the
given Git repo.

-- John

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [Newbie] Problem with Data.Map (or something else ?)

2008-03-31 Thread Bulat Ziganshin
Hello Bruno,

Monday, March 31, 2008, 7:51:43 PM, you wrote:

> I've written the following program... Which does not end in a reasonable time 
> :(
> My algorithm seems ok to me but I see that memory consumption is gigantic...
> Is this a memory problem with Data.Map ? Or an infinite loop ? (Where ?)
> In a more general way, how can I troubleshoot these kind of problem ?

first step is to reduce n and see whether program will finish and how
memreqs depends on value of n

> main =
> let n = 100


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] [Newbie] Problem with Data.Map (or something else ?)

2008-03-31 Thread Bruno Carnazzi
   Dears Haskellers,

As an Haskell newbie, I'm learning Haskell by trying to resolve Euler
Project problems (http://projecteuler.net/ ). I'm hanging on problem
14 (Collatz problem).

I've written the following program... Which does not end in a reasonable time :(
My algorithm seems ok to me but I see that memory consumption is gigantic...
Is this a memory problem with Data.Map ? Or an infinite loop ? (Where ?)
In a more general way, how can I troubleshoot these kind of problem ?

Here's the code :

import qualified Data.List as List
import qualified Data.Map as Map

f n | even n = n `div` 2
| otherwise = 3 * n + 1

chain m n =
let chain' cn cm | Map.member cn m = Map.map (+ (m Map.! cn)) cm
 | otherwise = chain' (f cn) $! Map.insert cn 1
(Map.map (+1) cm)
in chain' n Map.empty

chains n = List.foldl' (\m i -> Map.union m (chain m i))
(Map.singleton 1 1) [2..n]

maxCollatz c1@(_,l1) c2@(_,l2) | l1 < l2 = c2
   | otherwise = c1

maxChain = List.foldl' maxCollatz (0,0) . Map.toList . chains

main =
let n = 100
in putStrLn $ show $ maxChain n

Hope someone can help me, I really don't see what is th problem...

Best regards,

Bruno.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How can I represent 4x4 map in haskell

2008-03-31 Thread Tillmann Rendel
iliali16 wrote: 
> type Line = [Char]
> type Board = [Line]
> 
> so my question is if this is ok to represent a map. If yes I will try to
> write the function which makes it 4 x 4 myself. What I jsut need as an
> answer is Yes or No. Just to let you know is that I am trying to build the
> Wumpus World

A list of lists of cells is a possible representation for a two-dimensional
array, yes. for bigger maps, there may be a performance problem,
but for such a small world, it should be fine. 

You may consider using an array, e.g. with

  import Data.Array
  type Board = Array (Int, Int) Char 

Boards will be indexed by coordinate tuples.

Another point: maybe you should use an algebraic data type instead of
Char to represent the individual cells? e.g.

  data Cell = Wumpus | Trap | Gold | Nothing
  type Board = [[Cell]]

Be aware of the Wumpus! 

  Tillmann
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Homework wiki page (was Re: How can I represent 4x4 map in haskell)

2008-03-31 Thread Neil Mitchell
Hi Chris,

>  The Haskell community has a reputation of being helpful and welcoming to
>  newcomers.  I'm having a hard time reconciling that with this wiki page.
>  In particular.

For those who want to follow along, its this one:
http://haskell.org/haskellwiki/Homework_help

I agree. That page is pretty nasty. It looks like the person
summarised Eric Raymond's article, which is also pretty nasty. A
rewrite would be very good!

>  Let me be clear: I am not arguing that we should do people's homework for
>  them.  But I am arguing for changing the tone of the response.  I'd have
>  been rather put off if that wiki page had been my first introduction to
>  the Haskell community.

Yes. I think that we should suggest people ask homework questions to
homework authors, as they are based equipped to answer the questions
using the techniques and tools the students have been taught. But
politely, and saying why they benefit doing it the right way.

Thanks

Neil
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How can I represent 4x4 map in haskell

2008-03-31 Thread Janis Voigtlaender

iliali16 wrote:

Just to let you know that that is not a homework just for one function
representing the map. It is my project wich I subdivided into peaces but
since I am not that new to haskell I am not sure if I am on the right track
so that is my code till now:

type Line = [Char]
type Board = [Line]

so my question is if this is ok to represent a map. 


That certainly is one way to represent a map. For example, for any

  b::Board

you will be able to access elements via b !! i !! j for some i,j from 0 
to 3.


Whether it is the best choice of representation for your application 
very much depends on what you are going to do with it. For example, 
which kind of operations on boards you are going to need.


Just to mention an alternative: if it is important for your application 
that you always have exactly 4x4 maps, and you do not want to ensure 
this invariant "by hand", then you could use something along the lines of:


> type Quadruple a = (a,a,a,a)
> type Line = Quadruple Char
> type Board = Quadruple Line

Then, of course, you have to write your own "accessors" to get an 
element at position i,j.


(But there are several ways, differing in their level of complication, 
of making this more generic, rather than inventing your own Quadruple. 
Probably they are overkill for your goal.)


Ciao, Janis.

--
Dr. Janis Voigtlaender
http://wwwtcs.inf.tu-dresden.de/~voigt/
mailto:[EMAIL PROTECTED]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Homework wiki page (was Re: How can I represent 4x4 map in haskell)

2008-03-31 Thread Chris Smith
This is a little off-topic, but perhaps we can have some discussion of 
that Wiki page?

The Haskell community has a reputation of being helpful and welcoming to 
newcomers.  I'm having a hard time reconciling that with this wiki page.  
In particular.

1. The tone is generally threatening, as in: if you step over the line, 
you could be reported for cheating, so don't ask for too much help.

2. There's a general RTFM attitude.

3. There's a link to Eric Raymond's insulting article at the end, which 
goes on to inform people that we don't care about them, we are only here 
for our personal daily fix of mental challenge, and if they can't meet 
that then they've got no business wasting our time.

Let me be clear: I am not arguing that we should do people's homework for 
them.  But I am arguing for changing the tone of the response.  I'd have 
been rather put off if that wiki page had been my first introduction to 
the Haskell community.

-- 
Chris Smith

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How can I represent 4x4 map in haskell

2008-03-31 Thread iliali16

Just to let you know that that is not a homework just for one function
representing the map. It is my project wich I subdivided into peaces but
since I am not that new to haskell I am not sure if I am on the right track
so that is my code till now:

type Line = [Char]
type Board = [Line]

so my question is if this is ok to represent a map. If yes I will try to
write the function which makes it 4 x 4 myself. What I jsut need as an
answer is Yes or No. Just to let you know is that I am trying to build the
Wumpus World


iliali16 wrote:
> 
> Hi can you please tell me how can I represent 4x4 map in haskell.Should I
> show it as a list of lines and each line to be  a list of char or I am
> mistaken? Thanks in advance!
> 

-- 
View this message in context: 
http://www.nabble.com/How-can-I-represent-4x4-map-in-haskell-tp16396273p16396290.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: How can I represent 4x4 map in haskell

2008-03-31 Thread Chris Smith
iliali16 wrote:

> Hi can you please tell me how can I represent 4x4 map in haskell.Should
> I show it as a list of lines and each line to be  a list of char or I am
> mistaken? Thanks in advance!

What do you mean by a 4x4 map?  Maybe I'm missing something obvious, but 
there are several different meanings for "map", and I don't see which one 
you mean.

-- 
Chris Smith

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How can I represent 4x4 map in haskell

2008-03-31 Thread Janis Voigtlaender

iliali16 wrote:

Hi can you please tell me how can I represent 4x4 map in haskell.Should I
show it as a list of lines and each line to be  a list of char or I am
mistaken? Thanks in advance!


Sure this is no homework?

If it is, please first consult:

  http://www.haskell.org/haskellwiki/Homework_help

--
Dr. Janis Voigtlaender
http://wwwtcs.inf.tu-dresden.de/~voigt/
mailto:[EMAIL PROTECTED]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] How can I represent 4x4 map in haskell

2008-03-31 Thread iliali16

Hi can you please tell me how can I represent 4x4 map in haskell.Should I
show it as a list of lines and each line to be  a list of char or I am
mistaken? Thanks in advance!
-- 
View this message in context: 
http://www.nabble.com/How-can-I-represent-4x4-map-in-haskell-tp16396273p16396273.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] SYB with class: Bug in Derive.hs module

2008-03-31 Thread Alexey Rodriguez Yakushev

Hi people (and Ralf and Alex),

I found a bug in the SYB with class library when trying to implement  
generic equality. I am hoping that someone in the Cafe (maybe Ralf)  
can confirm it is a bug, or maybe show me that I am doing something  
wrong.


I am using the "Scrap your boilerplate with class" library (http:// 
homepages.cwi.nl/~ralf/syb3/). More precisely, I am using the library  
distributed by the HAppS project, because it works with GHC 6.8 . You  
can get the repository as follows:


darcs get http://happs.org/HAppS/syb-with-class

However, the offending module (Derive.hs) produces broken instances  
in both distributions.


The bug:
--

Generic equality needs type safe casting when implemented in SYB3, I  
have tried both the gzipwith variant and using Pack datatypes  
(geq*.hs in the first distribution). However, both functions loop  
when applied to a tree value.


This loop occurs when the functions try to cast one of the arguments.  
I have managed to reduce the error to a smaller source file that I  
send attached. It does the following:


> main = print typeReps
>
> tree = (Bin (Leaf 1) (Leaf 2))::BinTree Int
>
> data Pack = forall x. Typeable x => Pack x
>
> packedChildren = gmapQ geqCtx Pack tree
>
> typeOfPack (Pack x) = typeOf x
>
> typeReps = map typeOfPack packedChildren

Basically the tree is transformed into a list of Pack-ed values and  
then to a list of type representations. This program loops at  
"typeOf" when you call "main".


The Data instance that Derive generates is as follows:

> instance (Data ctx a,
>   Data ctx (BinTree a),
>   Sat (ctx (BinTree a))) =>
>   Data ctx (BinTree a) where

Note the recursive |Data ctx (BinTree a)| in the context. If I get  
rid of it (a correct manual instance is also included in the  
attachment) the example works.


I thought of removing this from the context in the Derive source. But  
maybe I might break some other use cases. So I am asking for help!  
Should Derive be fixed? How?


Cheers,

Alexey



BugBinTree.lhs
Description: Binary data
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] lexicographic order

2008-03-31 Thread Chaddaï Fouché
2008/3/31, Simeon Mattes <[EMAIL PROTECTED]>:
> why I should take as right
>
> (a,b) <= (a',b') iff (a < a' or (a == a' and b <= b'))
>
> and not
>
> (a,b) <= (a',b') iff (a <= a' or (a == a' and b <= b'))
>
>
> The latter seems more logical, doesn't it?

No, it doesn't, since in the latter (1,2) <= (1,1) because 1 <= 1

> Though I can't understand why both
> (Branch l r) <= (Branch l' r')  =  l < l' || l == l' && r <= r'
> (Branch l r) <= (Branch l' r')  =  l <= l' || l == l' && r <= r'
> give the same results

They don't, the second is a mistake, the first is the right one.

-- 
Jedaï
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Possible to automatically determine typeclass membership?

2008-03-31 Thread Alfonso Acosta
Hopefully, accessing the instance environment from Tempalte Haskell
will be possible in next GHC's release:

http://hackage.haskell.org/trac/ghc/ticket/1835

2008/3/31 jeff p <[EMAIL PROTECTED]>:
> Hello,
>
>
> > Is it possible in Haskell + GHC extensions to use reflection
> >  techniques to determine typeclass membership?  I'm thinking of things
> >  like the following:
> >
> I think the short answer is not in general; i.e. I don't think there is any
> way to access the members of an arbitrary typeclass (but I'd love to be
> proved wrong).
>
> However, you could always explicitly list the members of a typeclass you are
> interested in (this is similar to your Idea 2):
>
> {-# OPTIONS_GHC -fglasgow-exts -fallow-undecidable-instances
> -fallow-overlapping-instances #-}
>
> class InEq a b | a -> b where inEq :: a -> Bool
> instance TypeCast b HFalse => InEq a b where inEq _ = False
> instance InEq Int HTrue where inEq _ = True
> instance InEq a b => InEq [a] b where inEq _ = inEq (undefined :: a)
>
> data HTrue
> data HFalse
>
> class TypeCast   a b   | a -> b, b-> a   where typeCast   :: a -> b
> class TypeCast'  t a b | t a -> b, t b -> a where typeCast'  :: t -> a -> b
> class TypeCast'' t a b | t a -> b, t b -> a where typeCast'' :: t -> a -> b
>  instance TypeCast'  () a b => TypeCast a b where typeCast x = typeCast' ()
> x
> instance TypeCast'' t a b => TypeCast' t a b where typeCast' = typeCast''
> instance TypeCast'' () a a where typeCast'' _ x  = x
>
> You can also do an arguably nicer, more flexible version of the previous by
> recreating some of the typeclass machinery yourself; Oleg has several
> examples of this such as: //okmij.org/ftp/Haskell/poly2.txt
>
>  -Jeff
>
>
> ___
>  Haskell-Cafe mailing list
>  Haskell-Cafe@haskell.org
>  http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe