[Haskell-cafe] Showing 100% CPU usage of parallel code

2009-02-21 Thread Jim Burton

Hi, I copied the program below from a reddit post of dons'. I have a dual
core laptop with ubuntu hardy and ghc 6.10.1. I can see the difference when
I run the program with +RTS -N2 but CPU always says 100%. I'd like an
example that shows 100 -- is it not showing 100 because of my timeformat
or because of the program? If it's the latter can you point me to an example
that will use more cpu? 

Here's the output:

$ cat /proc/cpuinfo | grep processor | wc -l
2
$ export TIMEFORMAT=%E real,%U user,%S sys, %P cpu
$ ghc -O2 --make Par.hs -threaded
$ time ./Par
1405006117752879898543142606244511569936384005711076
2.330 real,2.328 user,0.000 sys, 99.92 cpu
$ time ./Par +RTS -N2
1405006117752879898543142606244511569936384005711076
1.504 real,2.316 user,0.016 sys, 100.00 cpu

Here's the program:


import Control.Parallel

main = a `par` b `par` c `pseq` print (a + b + c)
where
a = ack 3 10
b = fac 42
c = fib 34

fac 0 = 1
fac n = n * fac (n-1)

ack 0 n = n+1
ack m 0 = ack (m-1) 1
ack m n = ack (m-1) (ack m (n-1))

fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n-2)


Thanks,

Jim


-- 
View this message in context: 
http://www.nabble.com/Showing-%3E100--CPU-usage-of-parallel-code-tp22137081p22137081.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] Showing 100% CPU usage of parallel code

2009-02-21 Thread Jim Burton



Jeff Heard wrote:
 
 Jim, I'm actually not sure that time will report greater than 100% cpu
 on ubuntu hardy. (really not sure, and don't have it available right
 this moment to check).  I would however try making a computation that
 will take a little longer and use the system monitor or /proc to look
 at your CPU usage rather than time.  I've had good luck with GHC 6.8
 using  100% cpu, so I assume 6.10 will work much better.
 
 
Hi, thanks for that. The system monitor shows that I get ~160% usage, but
like you I don't know if it's possible to get time to display that (on
hardy, it clearly does elsewhere). The system monitor GUI is good enough, if
less neat than showing it via time. 

Jim


 
 
 On Sat, Feb 21, 2009 at 10:32 AM, Bulat Ziganshin
 bulat.zigans...@gmail.com wrote:
 Hello Jim,

 Saturday, February 21, 2009, 6:17:54 PM, you wrote:

 main = a `par` b `par` c `pseq` print (a + b + c)

 two things:
 1) that are grouping order? may be,
 a `par` (b `par` (c `pseq` print (a + b + c))) ?

 2) i recommend you to use 2 *same* computations.
 otherwise, it's easily possible that one of them needs much more time
 that the rest


 where
 a = ack 3 10
 b = fac 42
 c = fib 34

 fac 0 = 1
 fac n = n * fac (n-1)

 ack 0 n = n+1
 ack m 0 = ack (m-1) 1
 ack m n = ack (m-1) (ack m (n-1))

 fib 0 = 0
 fib 1 = 1
 fib n = fib (n-1) + fib (n-2)
 

 Thanks,

 Jim





 --
 Best regards,
  Bulatmailto:bulat.zigans...@gmail.com

 ___
 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
 
 

-- 
View this message in context: 
http://www.nabble.com/Showing-%3E100--CPU-usage-of-parallel-code-tp22137081p22137684.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] Elevator pitch for functional programming

2009-01-20 Thread Jim Burton
Hi, I will be a TA on a comparative PL course and I'm looking for
small examples (ammunition) which motivate the use of Haskell and
functional programming generally. The course is for 1st year Software
Engineers, none of whom are likely to have used a functional
language. They will all have experience programming Java and a little
C++, with a few of them knowing Python, Ruby, PHP etc etc too.

If anyone has code snippets which are the equivalent of an elevator
pitch for FP, I would be very grateful to see them. What I want
are some small concrete examples of idioms which are natural and
powerful in Haskell but difficult or impossible in, say, Java.

So I can produce examples of some of the things that make FP powerful,
elegant, expressive etc: higher order functions, polymorphism,
composition (ask them to write (.)  in Java :-)), partial application
and so on. I will point any interested souls to Hughes' great paper
[1]. But I have little time and it might be hard to put across why
they would want to do these things in the first place. I was looking
for something that speaks directly to the kind of problems they face
in languages like Java...

Types are a good example because Java programmers generally already
appreciate the help they get from compiler messages etc, so you can
sell a more flexible, enhanced form of this. Purity might appeal to
anyone who has longed to be able to reason about nastily complex code
with a lot of shared state. Laziness, streams? Hard to do in Java (I
presume) but also quite hard to sell the need.

The existence of an O'Reilly book will help, especially one that can
be sampled online, so I'll point them at RWH for extended concrete
examples. They will need to be already sold before they will bother
with that though.

Thanks,

Jim

[1] http://www.cs.chalmers.se/~rjmh/Papers/whyfp.html 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Elevator pitch for functional programming

2009-01-20 Thread Jim Burton

Adrian Neumann wrote:
 There was a thread about that:

   http://www.haskell.org/pipermail/haskell-cafe/2007-September/
 031402.html

Thanks! I didn't literally mean elevator pitch and if I knew that thread
existed would have phrased my post differently, because a list of the
things that are cool about Haskell will not impress them. What I want and
am finding it hard to create are examples where FP shines and, for the
same problem, imperative languages look like more work. Many will think of
programming solely in terms of developing websites, GUIs, database access,
so I will demonstrate how strongly-typed database access can help them.

Jim


 Am 20.01.2009 um 11:07 schrieb Jim Burton:

 Hi, I will be a TA on a comparative PL course and I'm looking for
 small examples (ammunition) which motivate the use of Haskell and
 functional programming generally. The course is for 1st year Software
 Engineers, none of whom are likely to have used a functional
 language. They will all have experience programming Java and a little
 C++, with a few of them knowing Python, Ruby, PHP etc etc too.

 If anyone has code snippets which are the equivalent of an elevator
 pitch for FP, I would be very grateful to see them. What I want
 are some small concrete examples of idioms which are natural and
 powerful in Haskell but difficult or impossible in, say, Java.

 So I can produce examples of some of the things that make FP powerful,
 elegant, expressive etc: higher order functions, polymorphism,
 composition (ask them to write (.)  in Java :-)), partial application
 and so on. I will point any interested souls to Hughes' great paper
 [1]. But I have little time and it might be hard to put across why
 they would want to do these things in the first place. I was looking
 for something that speaks directly to the kind of problems they face
 in languages like Java...

 Types are a good example because Java programmers generally already
 appreciate the help they get from compiler messages etc, so you can
 sell a more flexible, enhanced form of this. Purity might appeal to
 anyone who has longed to be able to reason about nastily complex code
 with a lot of shared state. Laziness, streams? Hard to do in Java (I
 presume) but also quite hard to sell the need.

 The existence of an O'Reilly book will help, especially one that can
 be sampled online, so I'll point them at RWH for extended concrete
 examples. They will need to be already sold before they will bother
 with that though.

 Thanks,

 Jim

 [1] http://www.cs.chalmers.se/~rjmh/Papers/whyfp.html
 ___
 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



-- 
Jim Burton

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


Re: [Haskell-cafe] Elevator pitch for functional programming

2009-01-20 Thread Jim Burton


Jim Burton wrote:
 
 
 Adrian Neumann wrote:
 There was a thread about that:

   http://www.haskell.org/pipermail/haskell-cafe/2007-September/
 031402.html
 
 Thanks! I didn't literally mean elevator pitch and if I knew that thread
 existed would have phrased my post differently, because a list of the
 things that are cool about Haskell will not impress them. What I want and
 am finding it hard to create are examples where FP shines and, for the
 same problem, imperative languages look like more work. 
 

Parallelism! Something based on dons' blog
http://cgi.cse.unsw.edu.au/~dons/blog/2007/11/29#smoking-4core will be a
good start.


Many will think of
 programming solely in terms of developing websites, GUIs, database access,
 so I will demonstrate how strongly-typed database access can help them.
 
 Jim
 
 [...]
 
 

-- 
View this message in context: 
http://www.nabble.com/Elevator-pitch-for-functional-programming-tp21560192p21565826.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] Elevator pitch for functional programming

2009-01-20 Thread Jim Burton
At Tue, 20 Jan 2009 12:25:00 -0800,
Dan Weston wrote:
 

Hi Dan,

 One of the coolest things about Haskell is the ability to refer to 
 values not yet calculated, without having to work out the timing yourself.
 
 You want Fibonacci numbers?
 

Well, I might but they definitely do not :-) We are talking about some
maths-averse people and you would not have got to the final syllable
of 'fibonacci' before all hope was lost. But I am sure there are 
plenty of examples that rely on laziness which will communicate. I am
sure I read a blog post or something on c.l.f/c.l.h recently about
lazily sorting a million numbers but can't find it. 

Jim

 Prelude let z = zipWith (+) (0:1:z) (0:z) in take 10 z
 [0,1,1,2,3,5,8,13,21,34]
 
 Try doing that in one line of C++.
 
 See also e.g.
 
 http://sigfpe.blogspot.com/2006/12/tying-knots-generically.html
 
 Dan
 
 Jim Burton wrote:
  
  Jim Burton wrote:
 
  Adrian Neumann wrote:
  There was a thread about that:
 
http://www.haskell.org/pipermail/haskell-cafe/2007-September/
  031402.html
  Thanks! I didn't literally mean elevator pitch and if I knew that thread
  existed would have phrased my post differently, because a list of the
  things that are cool about Haskell will not impress them. What I want and
  am finding it hard to create are examples where FP shines and, for the
  same problem, imperative languages look like more work. 
 
  
  Parallelism! Something based on dons' blog
  http://cgi.cse.unsw.edu.au/~dons/blog/2007/11/29#smoking-4core will be a
  good start.
  
  
  Many will think of
  programming solely in terms of developing websites, GUIs, database access,
  so I will demonstrate how strongly-typed database access can help them.
 
  Jim
 
  [...]
 
 
  
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Elevator pitch for functional programming

2009-01-20 Thread Jim Burton
At Tue, 20 Jan 2009 22:08:55 +0100,
Henning Thielemann wrote:
 
 Jim Burton schrieb:
 
  Well, I might but they definitely do not :-) We are talking about some
  maths-averse people and you would not have got to the final syllable
  of 'fibonacci' before all hope was lost. But I am sure there are 
  plenty of examples that rely on laziness which will communicate. I am
  sure I read a blog post or something on c.l.f/c.l.h recently about
  lazily sorting a million numbers but can't find it. 
 
 Maybe they are interested in finding all equal files in a set of files.
 This can be done in an elegant way by sorting the files with respect to
 their content. Practical enough?


Indeed, thanks!

Jim 
 http://hackage.haskell.org/cgi-bin/hackage-scripts/package/equal-files
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Elevator pitch for functional programming

2009-01-20 Thread Jim Burton
At Tue, 20 Jan 2009 14:17:10 -0800,
Ryan Ingram wrote:
 
 I recommend checking out Don Syme's slides from CUFP 2008.
 
 http://cufp.galois.com/2008/slides/
 
 This isn't Haskell directly, it's F#, but it fits the functional
 programming generally, and the two languages have, relative to the
 universe of programming languages, more in common than they do
 different.
 
 There's a lot of would you rather write this? with a giant chunk of
 C#, followed by or this? with a few readable lines of F#.


Hi, those slides look useful and inspiring. Thanks a lot.

Jim 

   -- ryan
 
 
 On Tue, Jan 20, 2009 at 2:07 AM, Jim Burton j...@sdf-eu.org wrote:
  Hi, I will be a TA on a comparative PL course and I'm looking for
  small examples (ammunition) which motivate the use of Haskell and
  functional programming generally. The course is for 1st year Software
  Engineers, none of whom are likely to have used a functional
  language. They will all have experience programming Java and a little
  C++, with a few of them knowing Python, Ruby, PHP etc etc too.
 
  If anyone has code snippets which are the equivalent of an elevator
  pitch for FP, I would be very grateful to see them. What I want
  are some small concrete examples of idioms which are natural and
  powerful in Haskell but difficult or impossible in, say, Java.
 
  So I can produce examples of some of the things that make FP powerful,
  elegant, expressive etc: higher order functions, polymorphism,
  composition (ask them to write (.)  in Java :-)), partial application
  and so on. I will point any interested souls to Hughes' great paper
  [1]. But I have little time and it might be hard to put across why
  they would want to do these things in the first place. I was looking
  for something that speaks directly to the kind of problems they face
  in languages like Java...
 
  Types are a good example because Java programmers generally already
  appreciate the help they get from compiler messages etc, so you can
  sell a more flexible, enhanced form of this. Purity might appeal to
  anyone who has longed to be able to reason about nastily complex code
  with a lot of shared state. Laziness, streams? Hard to do in Java (I
  presume) but also quite hard to sell the need.
 
  The existence of an O'Reilly book will help, especially one that can
  be sampled online, so I'll point them at RWH for extended concrete
  examples. They will need to be already sold before they will bother
  with that though.
 
  Thanks,
 
  Jim
 
  [1] http://www.cs.chalmers.se/~rjmh/Papers/whyfp.html
  ___
  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] Haskell versus F#, OCaml, et. al. ...

2008-09-30 Thread Jim Burton


Don Stewart-2 wrote:
 
 [...]
 Haskell was in the nice position
 of already having such a process underway, 
 
 http://haskell.org/haskellwiki/Haskell_Platform
 

Hi Don, I'm curious  -- what do the images on that page represent? Can you
link to readable versions? Thanks,

Jim



 Enjoy!
 
 -- Don
 ___
 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/Haskell-versus-F-%2C-OCaml%2C-et.-al.-...-tp19736848p19739995.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] Re: Help using Network.Curl

2008-07-21 Thread Jim Burton
At Mon, 21 Jul 2008 13:21:06 +0100,
=?ISO-8859-1?Q?Chadda=EF_Fouch=E9?= wrote:
 
 2008/7/19 Jim Burton [EMAIL PROTECTED]:
  opts = [CurlEncoding text/xml
, CurlHttpHeaders [X-EBAY-API-COMPATIBILITY-LEVEL=++compatLevel
  , X-EBAY-API-DEV-NAME=++devName
  , X-EBAY-API-APP-NAME=++appName
  , X-EBAY-API-CERT-NAME=++certName
  , X-EBAY-API-CALL-NAME=GeteBayOfficialTime
  , X-EBAY-API-SITEID=0]]
 
 Isn't it : rather than = ? Just saying... (Don't know enough to be
 sure I'm thinking about the right thing)

Is is indeed, thanks very much. I also had to change to using
`perform' rather than curlPost before it would work.

Cheers,

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


[Haskell-cafe] Re: Help using Network.Curl

2008-07-19 Thread Jim Burton
I tried to translate that using the Network.Curl docs and ended up with the
following code, but it's not sending the post data correctly (an ebay
api error re an unsupported verb, which I am told means a malformed
request). Any ideas? The code from a perl tutorial (which works for
me, making me think that my problem is just about the right way to
post xml to a web service) follows the haskell version, which is meant
to be a straight translation of that. 

Thanks,

Jim

--

[..skipped definitions of tokens etc..]

opts = [CurlEncoding text/xml
   , CurlHttpHeaders [X-EBAY-API-COMPATIBILITY-LEVEL=++compatLevel
 , X-EBAY-API-DEV-NAME=++devName
 , X-EBAY-API-APP-NAME=++appName
 , X-EBAY-API-CERT-NAME=++certName
 , X-EBAY-API-CALL-NAME=GeteBayOfficialTime
 , X-EBAY-API-SITEID=0]]

body = ?xml version='1.0' encoding='utf-8'? 
   ++ GeteBayOfficialTimeRequest 
xmlns=\urn:ebay:apis:eBLBaseComponents\ 
   ++   RequesterCredentials 
   ++ eBayAuthToken++token++/eBayAuthToken 
   ++   /RequesterCredentials 
   ++ /GeteBayOfficialTimeRequest

url = https://api.sandbox.ebay.com/ws/api.dll;

postData = HttpPost {postName  = body
, contentType  = Just text/xml
, content  = ContentString body
, extraHeaders = []
, showName = Nothing}

opts = []

--also tried using curlPost and setopts then perform... 
main = withCurlDo (do h - initialize
  curlMultiPost url opts [postData]
  )

---

Original perl:

use strict;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Headers;

# define the HTTP header
my $objHeader = HTTP::Headers-new;
$objHeader-push_header('X-EBAY-API-COMPATIBILITY-LEVEL' = '391');
$objHeader-push_header('X-EBAY-API-DEV-NAME' = 'yourdevname');
$objHeader-push_header('X-EBAY-API-APP-NAME' = 'yourappname');
$objHeader-push_header('X-EBAY-API-CERT-NAME' = 'yourcertname');
$objHeader-push_header('X-EBAY-API-CALL-NAME' = 'GeteBayOfficialTime');
$objHeader-push_header('X-EBAY-API-SITEID' = '0');
$objHeader-push_header('Content-Type' = 'text/xml');

# define the XML request
my $request =
?xml version='1.0' encoding='utf-8'? .
GeteBayOfficialTimeRequest xmlns=\urn:ebay:apis:eBLBaseComponents\ .
  RequesterCredentials .
eBayAuthTokenTOKENGoesHERE/eBayAuthToken .
  /RequesterCredentials .
/GeteBayOfficialTimeRequest;

# make the call
my $objRequest = HTTP::Request-new(
  POST,
  https://api.sandbox.ebay.com/ws/api.dll;,
  $objHeader,
  $request
);

# deal with the response
my $objUserAgent = LWP::UserAgent-new;
my $objResponse = $objUserAgent-request($objRequest);
if (!$objResponse-is_error) {
  print $objResponse-content;
}
else {
  print $objResponse-error_as_HTML;
}

--

This is what I get when running my version:

$ ./curlTest 
* About to connect() to api.sandbox.ebay.com port 443 (#0)
*   Trying 66.135.197.133... * connected
* Connected to api.sandbox.ebay.com (66.135.197.133) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: none
* SSL connection using AES256-SHA
* Server certificate:
*subject: /C=US/ST=California/L=San Jose/O=eBay Inc./OU=Site 
Operations/CN=api.sandbox.ebay.com
*start date: 2008-01-25 00:00:00 GMT
*expire date: 2010-03-15 23:59:59 GMT
*common name: api.sandbox.ebay.com (matched)
*issuer: /C=US/O=VeriSign, Inc./OU=VeriSign Trust Network/OU=Terms of 
use at https://www.verisign.com/rpa (c)05/CN=VeriSign Class 3 Secure Server CA
* SSL certificate verify ok.
 POST /ws/api.dll HTTP/1.1
Host: api.sandbox.ebay.com
Accept: */*
Accept-Encoding: text/xml
Content-Length: 1254
Expect: 100-continue
Content-Type: multipart/form-data; 
boundary=7c836e9408cd

 HTTP/1.1 100 Continue
 HTTP/1.1 200 OK
 Date: Sat, 19 Jul 2008 20:04:12 GMT
 Server: Microsoft-IIS/5.0
 X-EBAY-API-POOL-NAME: ___cDRidW90YmtiZWx9b2l3aQ==
 X-EBAY-API-SERVER-NAME: ___dXUucnVlYnVvNzM3KTYzKzc3LTI0KTQxPD8zPTc=
 Content-Type: text/xml
 Content-Length: 330
 X-Cache: MISS from sjcsbagpigw02.sjc.ebay.com, MISS from 
sjcsbagpigw02.sjc.ebay.com
 Connection: close
 
* Closing connection #0
?xml version=1.0 encoding=UTF-8 ?eBayEBayTime2008-07-19
20:04:55/EBayTimeErrorsErrorCode2/CodeErrorClassRequestError/ErrorClassSeverityCode1/SeverityCodeSeveritySeriousError/SeverityLine0/LineColumn0/ColumnShortMessage![CDATA[
Unsupported verb. ]]/ShortMessage/Error/Errors/eBay

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


[Haskell-cafe] Help using Network.Curl

2008-07-18 Thread Jim Burton
I want to convert this code (a Hello World with the ebay API)
 to the curl binding in the hope that it will handle SSL and
 redirections etc better. Can someone give me some pointers please, or
 a link to an example? I haven't used libcurl or Network.Curl and
 can't find anything helpful...Thanks!

-
import Network.URI
import Network.HTTP
import Network.Browser
import Data.Maybe (fromJust)

mkRequest :: Request
mkRequest = Request {
  rqURI = fromJust (parseURI 
https://api.sandbox.ebay.com/ws/api.dll;)
, rqMethod  = POST
, rqBody= body
, rqHeaders = headers
}

headers :: [Header]
headers = [Header HdrContentType text/xml
  , Header (HdrCustom X-EBAY-API-COMPATIBILITY-LEVEL) 391
  , Header (HdrCustom X-EBAY-API-DEV-NAME) DevName
  , Header (HdrCustom X-EBAY-API-APP-NAME) AppName
  , Header (HdrCustom X-EBAY-API-CERT-NAME) CertName
  , Header (HdrCustom X-EBAY-API-CALL-NAME) GeteBayOfficialTime
  , Header (HdrCustom X-EBAY-API-SITEID) 0
  ]

body = ?xml version='1.0' encoding='utf-8'? 
   ++ GeteBayOfficialTimeRequest 
xmlns=\urn:ebay:apis:eBLBaseComponents\ 
   ++   RequesterCredentials 
   ++ eBayAuthToken++MyToken++/eBayAuthToken 
   ++   /RequesterCredentials 
   ++ /GeteBayOfficialTimeRequest

main = do (_, resp) - browse (request mkRequest)
  print resp
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Lambda and closures in PHP -- could someone please comment?

2008-06-18 Thread Jim Burton



PR Stanley wrote:
 
 [...]
 
 Paul: I rest my case! :-)
 you cowardly hypocrit!
 
Please take your own advice now, and rest your case. Like it or not (I think
most people do like it), haskell-cafe has norms of behaviour that make it
different to many pl mailing lists. Your sarky comments would have gone
unnoticed if they had been accompanied with something constructive. Name
calling is out.

Jim


 ___
 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/Lambda-and-closures-in-PHPcould-someone-please-comment--tp17918732p17986275.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] Lambda and closures in PHP -- could someone please comment?

2008-06-18 Thread Jim Burton


PR Stanley wrote:
 
 
PR Stanley wrote:
 
  [...]
 
  Paul: I rest my case! :-)
  you cowardly hypocrit!
 
 Paul: Why did you remove Jonathan Cast's message? Afraid somebody 
 might understand why I responded the way I did?
 
 
Please take your own advice now, and rest your case. Like it or not (I
think
most people do like it), haskell-cafe has norms of behaviour that make it
different to many pl mailing lists. Your sarky comments would have gone
unnoticed if they had been accompanied with something constructive. Name
calling is out.
 Paul: and who the bloody hell are you to tell me what's in or out? If 
 you want the matter to rest then shut up yourself. I'm getting sick 
 of you hypocrites who allow yourselves the audacity to attack me, 
 totally gratuitously, yet when I try to defend myself you take the 
 moral high ground. Tell me, why did you remove Jonathan Cast's 
 message? Is he too big for you? Why don't you tell all the other 
 people who have been busy attacking me to modify their language? Are 
 you afraid of upsetting the Haskell Cafe Mafia?
 Well, guess what, you damn thugs, I 'aint taking this lying down.
 You come back with more and I'll give you even more!
 
I snipped Jonathan's message just because I was commenting on the tone of
your response. Sorry if you think I presented your reply out of context, but
my point is that I don't think there is any need for this in any context
here. I do have a right to say that, even as someone who hardly ever posts
but prefers to read the list...it's owned by everybody. This isn't the same
thing as censorship and you'll notice I said norms, not rules of behaviour.
No one's going to stop you making yourself look silly if you insist on doing
it. As for Jonathan being too big for me, erm, who is he again? :-)


 ___
 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/Lambda-and-closures-in-PHPcould-someone-please-comment--tp17918732p17987734.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] problem building array package

2008-01-18 Thread Jim Burton
Building array from cabal with ghc6.6:

~/array-0.1.0.0$ runhaskell Setup.hs configure
Configuring array-0.1.0.0...
~/array-0.1.0.0$ runhaskell Setup.hs build
Preprocessing library array-0.1.0.0...
Building array-0.1.0.0...
[ 1 of 10] Compiling Data.Array.Base  ( Data/Array/Base.hs,
dist/build/Data/Array/Base.o )

Data/Array/Base.hs:391:23: Not in scope: `Arr.numElements'

Data/Array/Base.hs:1067:35:
Not in scope: `ArrST.numElementsSTArray'

Data/Array/Base.hs:1079:51:
Not in scope: `ArrST.numElementsSTArray'


Any ideas why? Thanks,

Jim

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


[Haskell-cafe] Hoogle error

2007-12-13 Thread jim burton
Hoogling (-) (=) gives

Error, your search was invalid:
Parse Error: Unexpected character '=)'

Is there a way to escape the input so it would work? (I wasn't really
expecting the right results BTW as I think hoogle searches type
signatures not patterns in definitions, right?)

Thanks,

Jim

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


Re: [Haskell-cafe] Hoogle error

2007-12-13 Thread jim burton
On Thu, 2007-12-13 at 20:16 +, Neil Mitchell wrote:
 Hi
 
  Hoogling (-) (=) gives
 
  Error, your search was invalid:
  Parse Error: Unexpected character '=)'
 
  Is there a way to escape the input so it would work? (I wasn't really
  expecting the right results BTW as I think hoogle searches type
  signatures not patterns in definitions, right?)
 
 What were you expecting it to give you as an answer?

Hi. Sorry, I should have put the question differently -- is there
sometimes a need to escape hoogle input (i.e. so I could confirm there
were no results, rather than getting an error)? But, thinking about it,
there's no reason that this shouldn't give an error as it isn't a type
sig. (I was looking for source online somewhere of the monad instance
for (-) and only entered it in hoogle out of curiosity...) Sorry to
waste your time! As you were :-)

Jim

 
 Either you want a function named =, in which case you have to search
 for = - not (=) as that won't work. This is something I plan
 to rectify in Hoogle 4.
 
 Or you want a function which takes a function as its first argument.
 (a - b) - c will give you this - but not find (=) ever.
 
 Thanks
 
 Neil
 

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


[Haskell-cafe] fundeps and overlapping/undecidable instances

2007-12-07 Thread Jim Burton

I have some type-level sets using fundeps working whereby equality and
membership etc are predicate functions. This seems to leads to an explosion
of ugly code, with `If' class constraints etc getting out of hand -- I want
to treat these as relations instead so providing the definition describes
everything that is 'in' and nothing that is 'out'. I've been using Oleg's
paper on lightweight static resources [1] as a template for this. I want to
do something like this (supposing I have an EQ relation, (:::) for consing):

class Member x y 
instance EQ x y  = Member x (y:::ys) 
instance Member x ys = Member x (y:::ys)

But I can certainly see why this isn't possible (It's the equivalent of
pattern-matching on the constraints I suppose). Do type families provide a
way to do this kind of thing or do I need a different strategy altogether,
involving GADTs or whatever?

Thanks,

[1] http://okmij.org/ftp/Computation/resource-aware-prog/tfp.pdf
-- 
View this message in context: 
http://www.nabble.com/fundeps-and-overlapping-undecidable-instances-tf4962996.html#a14215583
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] fundeps and overlapping/undecidable instances

2007-12-07 Thread jim burton
On Fri, 2007-12-07 at 12:49 -0500, Jeff Polakow wrote:
 
 Hello, 

   You should be able to use fundeps to do exactly what you describe
 below. 
 
   Can you make a relatively small self-contained example which
 exemplifies the ugliness you see? 
 

Hi Jeff, as well as a minor code explosion if Member returns a (phantom
type representing a) boolean then you have to decide what to do if the
element is already in -- return the set unchanged I should think, but in
other cases it might not be obvious so I want this and other things to
be relations. So I had

class If p x y c | p x y - c
where if :: p - x - y - c
instance If True x y x
instance If False x y y

class Member el set b | el set - b
where member :: el - set - b
instance x Nil False
instance (Eq x y c
, Member x ys b 
, Or c d b) =
Member x (y ::: ys) b

(Eq and Or being more constraints that return True or False) I want a
version that is only defined where the element is in the set -- not a
test, an assertion. 

Jim

 -Jeff 
 
 
 [EMAIL PROTECTED] wrote on 12/07/2007 11:24:35 AM:
 
  
  I have some type-level sets using fundeps working whereby equality
 and
  membership etc are predicate functions. This seems to leads to an
 explosion
  of ugly code, with `If' class constraints etc getting out of hand --
 I want
  to treat these as relations instead so providing the definition
 describes
  everything that is 'in' and nothing that is 'out'. I've been using
 Oleg's
  paper on lightweight static resources [1] as a template for this. I
 want to
  do something like this (supposing I have an EQ relation, (:::) for
 consing):
  
  class Member x y 
  instance EQ x y  = Member x (y:::ys) 
  instance Member x ys = Member x (y:::ys)
  
  But I can certainly see why this isn't possible (It's the equivalent
 of
  pattern-matching on the constraints I suppose). Do type families
 provide a
  way to do this kind of thing or do I need a different strategy
 altogether,
  involving GADTs or whatever?
  
  Thanks,
  
  [1] http://okmij.org/ftp/Computation/resource-aware-prog/tfp.pdf
  -- 
  View this message in context: http://www.nabble.com/fundeps-and-
  overlapping-undecidable-instances-tf4962996.html#a14215583
  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
 
 ---
 
 This e-mail may contain confidential and/or privileged information. If
 you 
 are not the intended recipient (or have received this e-mail in
 error) 
 please notify the sender immediately and destroy this e-mail. Any 
 unauthorized copying, disclosure or distribution of the material in
 this 
 e-mail is strictly forbidden.

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


Re: [Haskell-cafe] HTTP actions proxy server

2007-11-20 Thread Jim Burton

Thank you, that's perfect.

Jim 

stefan kersten-2 wrote:
 
 On 16.11.2007, at 13:55, Jim Burton wrote:
 The docs say Should be of the form http://host:port, host,  
 host:port, or
 http://host; but none of the variations work. Any ideas where I  
 might find
 an example of code that does this?
 
 this works for me (modulo error handling):
 
 simpleHTTP' :: Request - IO (Result Response)
 simpleHTTP' req = do
  proxy - catch
  (getEnv HTTP_PROXY = return . (flip Proxy Nothing))
  (\_ - return NoProxy)
  (_, resp) - browse (setProxy proxy  request req)
  return (Right resp)
 
 i.e. run the request in the browser monad.
 
 sk
 
 ___
 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/HTTP-actions---proxy-server-tf4815272.html#a13853610
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] HTTP actions proxy server

2007-11-16 Thread Jim Burton


Justin Bailey wrote:
 
 
 I think it needs to be a real URL:
 
   setProxy (Proxy http://myproxy:80; Nothing)
 
 Justin
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 
The docs say Should be of the form http://host:port, host, host:port, or
http://host; but none of the variations work. Any ideas where I might find
an example of code that does this?

-- 
View this message in context: 
http://www.nabble.com/HTTP-actions---proxy-server-tf4815272.html#a13792542
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] HTTP actions proxy server

2007-11-15 Thread Jim Burton

How would I go about converting the little get program at
http://darcs.haskell.org/http/test/get.hs to use a proxy server? I tried
adding a call to setProxy like this but it doesn't work:

get :: URI - IO String
get uri =
do
  browse $ setProxy (Proxy myproxy:80 Nothing)
  eresp - simpleHTTP (request uri)
  resp - handleE (err . show) eresp
  case rspCode resp of
(2,0,0) - return (rspBody resp)
_ - err (httpError resp)
  where
showRspCode (a,b,c) = map intToDigit [a,b,c]
httpError resp = showRspCode (rspCode resp) ++   ++
rspReason resp

Thanks.
-- 
View this message in context: 
http://www.nabble.com/HTTP-actions---proxy-server-tf4815272.html#a13775608
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] Upgrading X11

2007-11-12 Thread jim burton
On Sun, 2007-11-11 at 12:44 -0500, Brent Yorgey wrote:

 
 I think you need to run autoconf  autoheader  (or autoreconf) first,
 before running Setup configure?  I could be confused, but see if that
 helps.  If that's what the problem is, the documentation definitely
 needs updating. 
 
 -Brent
 
 

Thanks Brent, autoconf  autoheader fixed it. I won't volunteer to look
at the docs because I have no idea why!

Jim

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


[Haskell-cafe] Upgrading X11

2007-11-11 Thread Jim Burton

I have X11 1.2.2 installed and wanted to upgrade to 1.3 (to satisfy the
dependencies of another package), but Setup configure tells me I don't
have the headers installed. I do, and when I configure 1.2.2 they're
detected. Is this due to the newer version of Cabal? I have ghc 6.6, Cabal
1.1.6.

Thanks,
-- 
View this message in context: 
http://www.nabble.com/Upgrading-X11-tf4785984.html#a13691779
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] Compiling GHC on Scientific Linux V5 [http://ftp.scientificlinux.org/linux/scientific/50/iso/i386/SL-5.0-050407-i386-DVD.iso, Build on RHEL5]

2007-11-05 Thread Jim Burton


Animesh Sharma wrote:
 
 [...]
 Now I have to dig deeper into the release note
 (http://www.haskell.org/ghc/docs/6.8.1/html/users_guide/release-6-8-1.html
 ), one thing which has really got me interested is the introduction of
 debugger to GHCi. Any tutorials on how to go about it?
 
Hi Animesh, the User's Guide is the place to go --
http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html


 Regards,
 
 Ani
 
 
 
 -The Answer lies in the Genome
 fuzzylife.org
 
 ___
 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/Compiling-GHC-on-Scientific-Linux-V5--http%3A--ftp.scientificlinux.org-linux-scientific-50-iso-i386-SL-5.0-050407-i386-DVD.iso%2C-Build-on-RHEL5--tf4751963.html#a13590339
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] Disjunctive Normal Form

2007-11-01 Thread Jim Burton

I am trying to rewrite sentences in a logical language into DNF, and wonder
if someone would point out where I'm going wrong. My dim understanding of it
is that I need to move And and Not inwards and Or out, but the function
below fails, for example:

 dnf (Or (And A B) (Or (And C D) E))
And (Or A (And (Or C E) (Or D E))) (Or B (And (Or C E) (Or D E)))


data LS = Var | Not LS | And LS LS | Or LS LS
--convert sentences to DNF
dnf :: LS - LS
dnf (And (Or s1 s2) s3) = Or (And (dnf s1) (dnf s3)) (And (dnf s2) (dnf s3))
dnf (And s1 (Or s2 s3)) = Or (And (dnf s1) (dnf s2)) (And (dnf s1) (dnf s3))
dnf (And s1 s2) = And (dnf s1) (dnf s2)
dnf (Or s1 s2)  = Or (dnf s1) (dnf s2)
dnf (Not (Not d))   = dnf d
dnf (Not (And s1 s2))   = Or (Not (dnf s1)) (Not (dnf s2))
dnf (Not (Or s1 s2))= And (Not (dnf s1)) (Not (dnf s2))
dnf s   = s

Thanks,

Jim

-- 
View this message in context: 
http://www.nabble.com/Disjunctive-Normal-Form-tf4733248.html#a13534567
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] Backpatching

2007-08-01 Thread Jim Burton


Derek Elkins wrote:
 
 On Tue, 2007-07-31 at 23:04 -0700, Stefan O'Rear wrote:
 On Wed, Aug 01, 2007 at 03:44:32PM +1000, Thomas Conway wrote:
  This sounds like a common problem type. Is there a well known solution
  to this sort of problem?
 
 Mmm... logic programming?
 
 http://citeseer.ist.psu.edu/claessen00typed.html
 
 You'll only need the code for logic-variables, and even that can be
 simplified because your terms are non-recursive.  (Even in the
 recursive case, a logic program like a HM typechecker usually only needs
 ~50 lines of prelude).
 
 If someone is interested, I did transcribe and mildly generalize the
 code from that paper.
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 

Hi Derek, I'd be interested in looking at that -- have you put it online?

-- 
View this message in context: 
http://www.nabble.com/Backpatching-tf4198168.html#a11945491
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] Hints for Euler Problem 11

2007-07-20 Thread Jim Burton


Ronald Guida wrote:
 
 Hi, again.
 
 I started looking at the Euler problems [1].  I had no trouble with
 problems 1 through 10, but I'm stuck on problem 11.  I am aware that
 the solutions are available ([2]), but I would rather not look just
 yet.
 [...]
 
 

FWIW I used a 2D array and a function to retrieve the values in every
direction from a given row,col, for each direction valid for that array
index. Getting the 4 vals in each direction is done by iterating 2 functions
on the (row,col) index to move in the right direction I.e., 

vals (row,col) = north : south : ... : []
  where north = if toohigh then [] else stream (subtract 1) (id)
   south = if toolow then [] else stream (+1) (id)
   ...

-- 
View this message in context: 
http://www.nabble.com/Hints-for-Euler-Problem-11-tf4114963.html#a11710468
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] Hints for Euler Problem 11

2007-07-20 Thread Jim Burton


Jim Burton wrote:
 
 
 Ronald Guida wrote:
 
 Hi, again.
 
 I started looking at the Euler problems [1].  I had no trouble with
 problems 1 through 10, but I'm stuck on problem 11.  I am aware that
 the solutions are available ([2]), but I would rather not look just
 yet.
 [...]
 
 
 
 FWIW I used a 2D array and a function to retrieve the values in every
 direction from a given row,col, for each direction valid for that array
 index. Getting the 4 vals in each direction is done by iterating 2
 functions on the (row,col) index to move in the right direction I.e., 
 
 vals (row,col) = north : south : ... : []
   where north = if toohigh then [] else stream (subtract 1) (id)
south = if toolow then [] else stream (+1) (id)
...
 
 
where `stream' is badly named -- rather than a stream it's the 4 vals in
that direction.

-- 
View this message in context: 
http://www.nabble.com/Hints-for-Euler-Problem-11-tf4114963.html#a11710683
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: Maintaining the community

2007-07-13 Thread Jim Burton



Simon Peyton-Jones wrote:
 
 [...]
 We need at least one forum in which it's acceptable to ask anything, no
 matter how naive, and get polite replies.  (RTFM isn't polite; but The
 answer is supposed to be documented here (\url); let us know if that
 doesn't answer your qn is fine.)   I'd be sorry to lose that.
 

I fully agree and I don't mean RTFM literally. The answer is supposed to be
documented here (\url)... is a very acceptable form of it...one can be
brisk without being rude and I'm always grateful when someone points me in
the direction of the right manual - if it's currently beyond my ken and I
need to read something else first then that's my problem. I'm not going to
waste your time by expecting you to read it for me and give quick answers to
deep questions.
-- 
View this message in context: 
http://www.nabble.com/Maintaining-the-community-tf4071917.html#a11577502
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] Maintaining the community

2007-07-13 Thread Jim Burton



Jules Bean wrote:
 
 Jim Burton wrote:
 Very timely! It's sad that haskell-cafe has so much noise now.
 
 I disagree with that characterisation. I don't mean to be pedantic, but 
 I don't think haskell-cafe has lots of noise. I think it has lots of 
 signal! Quite different.
 
 
I think you're right actually. I was exaggerating the problem due to having
woken up as a bad tempered spartan.


 [...]
 
   One way of protecting the community is to protect this list from
 drowning
   in noise and being a bit rough with newbies who don't do any research
 at
   all before asking is perfectly acceptable in my view.
 
 I disagree with that on two separate levels:
 
 (a) I don't think being rough with newbies is the right response.
 (b) I also don't think it would achieve the goal you state. Being rough 
 with one newbie will not, in my experience, particularly prevent the 
 next question asked by the next newbie :)
 
 All IMHO, obviously.
 
 Jules
 
 
You notice I said people who do no research at all? It might be unfriendly
and counter to the way things happen here, but I think the most helpful
response is to tell them to do some research.

-- 
View this message in context: 
http://www.nabble.com/Maintaining-the-community-tf4071917.html#a11577694
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] Maintaining the community

2007-07-13 Thread Jim Burton



Donald Bruce Stewart wrote:
 
 As we sit here riding the Haskell wave:
 
 [...]
 
 * Give tips on how to answer questions
 
 Answering politely, and in detail, explaining common
 misunderstandings
 is better than one word replies.
 
 
 * Adopt a near-zero-tolerance Be Nice policy when people answer
 questions
 
 We are very good here already, both on email and IRC.
 
 
Very timely! It's sad that haskell-cafe has so much noise now. I haven't
been around very long at all but it has gone downhill dramatically even in
the last 6 months (I think I could put a date on it but lets not get into
that). As well as being nice, can't you sometimes tell people to RTFM? Or,
You've asked that before, or That's an FAQ, search the archive? One way of
protecting the community is to protect this list from drowning in noise and
being a bit rough with newbies who don't do any research at all before
asking is perfectly acceptable in my view. It goes without saying that
everything you say about the quality of the help here is true but I don't
think you should treat us with kid gloves. 

-- 
View this message in context: 
http://www.nabble.com/Maintaining-the-community-tf4071917.html#a11576127
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] Very freaky

2007-07-11 Thread Jim Burton


Andrew Coppin wrote:
 
 Jim Burton wrote:
 Andrew Coppin wrote:
   
 On the one hand, it feels exciting to be around a programming language 
 where there are deep theoretical discoveries and new design territories 
 to be explored. (Compared to Haskell, the whole C / C++ / Java / 
 JavaScript / Delphi / VisualBasic / Perl / Python thing seems so
 boring.)

 On the other hand... WHAT THE HECK DOES ALL THAT TEXT *MEAN*?! _


 
 I agree, it's exciting to use Haskell because of its theoretical
 underpinning and the sense of it as a lab for PL ideas.
 
 The other downside is that you end up with a world where most of the 
 tools are in fact one-man research projects or small toys.
 
 There are a few good, powerful, useful things out there. (GHC and Parsec 
 immediately spring to mind.) But there's also a vast number of really 
 tiny projects which don't seem to be terrifically well supported. Kind 
 of makes me sad; Haskell seems almost doomed to be a language with 
 fantastic potential, but little real-world traction.
 
AFAIK Haskell wasn't designed for real-world traction in the first place,
but as a way of consolidating FP research efforts onto one platform, so in
that sense it's a resounding success rather than doomed. It also seems to
have gained some traction, and we know that FP can be an eminently practical
real-world secret weapon, so the tools you're waiting for someone else to
write could well be on their way. At the same time, the only evidence for
this at the moment is a lot of blogs, O'Reilly investing in a book and
Eternal September on haskell-cafe. If you want a language with a bigger user
base or that is less confusing, there are plenty to choose from.

-- 
View this message in context: 
http://www.nabble.com/Very-freaky-tf4057907.html#a11547225
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] CGI test

2007-07-10 Thread Jim Burton



Andrew Coppin wrote:
 
 Greetings.
 
 Can somebody write a trivial (as in: small) program so I can test my CGI 
 stuff without having to actually install and configure Apache?
 
 [...]
 
You could adapt the TCP server from this tutorial -
http://sequence.complete.org/node/258 

Regards,
-- 
View this message in context: 
http://www.nabble.com/CGI-test-tf4058260.html#a11529701
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] Very freaky

2007-07-10 Thread Jim Burton


Andrew Coppin wrote:
 
 
 On the one hand, it feels exciting to be around a programming language 
 where there are deep theoretical discoveries and new design territories 
 to be explored. (Compared to Haskell, the whole C / C++ / Java / 
 JavaScript / Delphi / VisualBasic / Perl / Python thing seems so boring.)
 
 On the other hand... WHAT THE HECK DOES ALL THAT TEXT *MEAN*?! _
 
 
I agree, it's exciting to use Haskell because of its theoretical
underpinning and the sense of it as a lab for PL ideas. The cost of taking
part in that (even as an observer) is the background knowledge and common
vocabulary you need in order to make sense of a lot of the papers that you
may get referred to, presuming you start asking the kind of questions that
elicit answers like that. I don't think the amount of background knowledge
required is actually that big but if it's missing you will feel like you're
going one step forwards and two steps back. 

The Getting Started thread on Lambda the Ultimate is good  - maybe we need
a wikipage like that but of links to sources of the type theoretical
background to Haskell (is there one already? I see Research Papers, which
obviously has a different purpose). 

I don't know where the best place to start would be but, as I said in
another thread Andrew, TAPL is great. Re. Curry-Howard, have a look Simon
Thompson's book (online for free)
http://www.cs.kent.ac.uk/people/staff/sjt/TTFP/  . Not quick reads (by any
means!), but depending on your learning style, better value than asking ad
hoc questions and joining the dots via blog posts/wiki pages etc.

-- 
View this message in context: 
http://www.nabble.com/Very-freaky-tf4057907.html#a11530874
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] Problem using ap -- No instance for (Monad ((-) [[a]]))

2007-07-06 Thread Jim Burton

If I try  a function to make a point-free version of the function in this
fold --

foldr (\x ys - ys ++ map (x:) ys) [[]]

:pl gives me

GOA Control.Monad :pl (\x ys - ys ++ map (x:) ys)
 ap (++) . map . (:)
GOA Control.Monad :t  ap (++) . map . (:)
ap (++) . map . (:) :: (Monad ((-) [[a]])) = a - [[a]] - [[a]]

but this is what happens if I try to use it:

GOA Control.Monad let ps = foldr (ap (++) . map . (:)) [[]]

interactive:1:16:
No instance for (Monad ((-) [[a]]))
  arising from use of `ap' at interactive:1:16-22
Possible fix: add an instance declaration for (Monad ((-) [[a]]))
In the first argument of `(.)', namely `ap (++)'
In the first argument of `foldr', namely
`((ap (++)) . (map . (:)))'
In the expression: foldr ((ap (++)) . (map . (:))) [[]]
(0.00 secs, 0 bytes)

What gives?



-- 
View this message in context: 
http://www.nabble.com/Problem-using-apNo-instance-for-%28Monad-%28%28-%3E%29---a--%29%29-tf4036243.html#a11466625
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] N00b question

2007-07-02 Thread Jim Burton


poop wrote:
 
 So I'm working my way thorough haskell, doing some programming problems,
 and I have this one so far:
 
Hi, I haven't spotted the problem in your code but there's an alternative
solution to Euler Problem 14 on the wiki:
http://www.haskell.org/haskellwiki/Euler_problems/11_to_20#Problem_14 -- it
may be helpful as a comparison?
Regards,


 p14next n = if (mod n 2 == 0) then (div n 2) else (3*n + 1)
 
 p14seqlen n = f' 1 n where
   f' accum n
   | n == 1= accum
   | otherwise = f' (accum + 1) (p14next n)
 
 sndmax a b = if snd a  snd b then a else b
 
 p14 n = fst (f' (0,0) n) where
   f' maxTuple n
   | n == 0= maxTuple
   | otherwise = f' (sndmax maxTuple (n, p14seqlen n)) (n-1)
 
 the goal is to be able to run:
 p14 99
 
 and not get a stack overflow message.  I read what was available on tail
 recursion and I think I have it working with tail recursion now, at least
 it gives me a stack overflow message really quickly compared to before :)
 
 I have not been able to find any documentation on seq and ($!) which was
 also mentioned as a way to get rid of stack overflow messages so if those
 are what is required an explanation of those would be most helpful.
 
 

-- 
View this message in context: 
http://www.nabble.com/N00b-question-tf4010616.html#a11395620
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] Sneaking haskell in the workplace -- cleaning csv files

2007-06-16 Thread Jim Burton

Tomasz Zielonka wrote:

On Fri, Jun 15, 2007 at 11:31:36PM +0100, Jim Burton wrote:
I think that would only work if there was one column per line...I didn't 
make it clear that as well as being comma separated, the delimiter is 
around each column, of which there are several on a line so if the 
delimiter is ~ a file might look like:


~sdlkfj~, ~dsdkjf~ #eo row1
~sdf
dfkj~, ~dfsd~  #eo row 2


It would be easier to experiment if you could provide us with an
example input file. If you are worried about revealing sensitive
information, you can change all characters other then newline,
~ and , to As, for example. An accompanying output file, for checking
correctness, would be even nicer.

Hi Tomasz, I can do that but they do essentially look like the example 
above, except with 10 - 30 columns, more data in each column, and more 
rows, maybe this side of a million. They are produced by an Oracle 
export which escapes the delimiter (often a tilde) from within the cols. 
The output file should have exactly one row per line, with extra 
newlines replaced by a string given as a param (it might be a space or a 
html tag -- I only just remembered this and my initial effort doesn't do 
it).


Thanks,

Jim


Best regards
Tomek



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


Re: [Haskell-cafe] Sneaking haskell in the workplace -- cleaning csv files

2007-06-16 Thread Jim Burton

Tomasz Zielonka wrote:


I guess you've tried to convince Oracle to produce the right format in
the first place, so there would be no need for post-processing...?


We don't control that job or the first db.



I wonder what would you get if you set the delimiter to be a newline ;-)


eek! ;-)


Best regards
Tomek



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


[Haskell-cafe] Sneaking haskell in the workplace -- cleaning csv files

2007-06-15 Thread Jim Burton

I need to remove newlines from csv files (within columns, not at the end of
entire lines). This is prior to importing into a database and was being done
at my workplace by a java class for quite a while until the files processed
got bigger and it proved to be too slow. (The files are up to ~250MB at the
moment) It was rewritten in PL/SQL, to run after the import, which was an
improvement, but it still has our creaky db server thrashing away. (You may
have lots of helpful suggestions in mind, but we can't clean the data at
source and AFAIK we can't do it incrementally because there is no timestamp
or anything on the last change to a row from the legacy db.) 

We don't need a general solution - if a line ends with a delimiter we can be
sure it's the end of the entire line because that's the way the csv files
are generated.

I had a quick go with ByteString (with no attempt at robustness etc) and
although I haven't compared it properly it seems faster than what we have
now. But you can easily make it faster, surely! Hints for improvement please
(e.g. can I unbox anything, make anything strict, or is that handled by
ByteString, is there a more efficient library function to replace the
fold...?).

module Main
where
import System.Environment (getArgs)
import qualified Data.ByteString.Char8 as B

--remove newlines in the middle of 'columns'
clean :: Char - [B.ByteString] - [B.ByteString]
clean d = foldr (\x ys - if B.null x || B.last x == d then x:ys else
(B.append x $ head ys):(tail ys)) [] 

main = do args - getArgs
  if length args  2
   then putStrLn Usage: crunchFile INFILE OUTFILE [DELIM]
   else do bs - B.readFile (args!!0)
   let d = if length args == 3 then head (args!!2) else ''
   B.writeFile (args!!1) $ (B.unlines . clean d . B.lines)
bs


Thanks,

Jim
-- 
View this message in context: 
http://www.nabble.com/Sneaking-haskell-in-the-workplacecleaning-csv-files-tf3928931.html#a11142895
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] Sneaking haskell in the workplace -- cleaning csv files

2007-06-15 Thread Jim Burton

Thomas Schilling wrote:


On 15 jun 2007, at 18.13, Jim Burton wrote:



import qualified Data.ByteString.Char8 as B



Have you tried

import qualified Data.ByteString.Lazy.Char8 as B

?



No -- I'll give it a try and compare them. Is laziness preferable here?

Thanks,






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


Re: [Haskell-cafe] Sneaking haskell in the workplace -- cleaning csv files

2007-06-15 Thread Jim Burton

Sebastian Sylvan wrote:

On 15/06/07, Jim Burton [EMAIL PROTECTED] wrote:

[snip]

Hi,

Hi Sebastian,

I haven't compiled this, but you get the general idea:

import qualified Data.ByteString.Lazy.Char8 as B
-- takes a bytestring representing the file, concats the lines
-- then splits it up into real lines using the delimiter
clean :: Char - B.ByteString - [B.ByteString]
clean' d = B.split d . B.concat . B.lines


I think that would only work if there was one column per line...I didn't 
make it clear that as well as being comma separated, the delimiter is 
around each column, of which there are several on a line so if the 
delimiter is ~ a file might look like:


~sdlkfj~, ~dsdkjf~ #eo row1
~sdf
dfkj~, ~dfsd~  #eo row 2






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


Re: [Haskell-cafe] Sneaking haskell in the workplace -- cleaning csv files

2007-06-15 Thread Jim Burton

Jason Dagit wrote:
[snip]


I love to see people using Haskell, especially professionally, but I
have to wonder if the real tool for this job is sed? :-)

Jason


Maybe it is -- I've never used sed. (cue oohs and ahhs from the 
gallery?) But from the (unquantified) gains so far haskell may certainly 
be enough of an improvement to fit the bill even though I'd be 
interested in anything that improved on it further still.

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


Re: [Haskell-cafe] Sneaking haskell in the workplace -- cleaning csv files

2007-06-15 Thread Jim Burton

Sebastian Sylvan wrote:


A sorry, I thought the delimiter was a line delimiter. I'm trying to get to
that fusion goodness by using built-in functions as much as possible...

How about this one:

clean del = B.map ( B.filter (/='\n') ) . B.groupBy (\x y - (x,y) /=
(del,'\n'))

That groupBy will group it into groups which don't have the delimiter
followed by a newline in them (which is the sequence your rows end with),
then it filters out newlines in each row. You might want to filter out
spaces first (if there are any) so that you don't get a space between the
delimiter and newline at the end...


I think you still need unlines after that so is the time complexity 
different to the


unlines . foldr (function including `last') . lines

in my first post? Or is it better for another reason, such as fusion 
goodness?

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


Re: [Haskell-cafe] Language extensions

2007-05-28 Thread Jim Burton



Andrew Coppin wrote:
 
 
 Haskell 98 does an excellent job of being extremely simple, yet almost 
 unbelievably powerful. Almost every day, I am blown away by how powerful 
 it is. I suppose it just defies belief that you could possibly need even 
 *more* power than is already in the language... 
 

Sounds like the blub paradox ;-) 



 and also, as I've 
 mentioned, Haskell being simple is one of the most appealing things 
 about it. I dislike conceptual complexity. Still, it's only my personal 
 opinion, and the decision isn't actually up to me...
 
 ___
 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/Memoization-tf3822500.html#a10832782
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] Language extensions

2007-05-27 Thread Jim Burton



Andrew Coppin wrote:
 
 
 [snip]
 You're missing a lot of the conceptual background
 
 Possibly. I find that most of what is written about Haskell tends to be 
 aimed at absolute beginners, or at people with multiple PhDs. (As in, 
 people to whom arcane terms like denotational semantics actually 
 *means* something.) I remember seeing somebody wrote a game (!!) in 
 Haskell - despite the fact that this is obviously impossible. So I went 
 to read the paper about how they did it... and rapidly become completely 
 lost. I get that they used something called funtional reactive 
 programming, but I am still mystified as to what on earth that actually 
 is, or how it functions.
 
 But an awful lot 
 of the more popular extensions are primarily about relaxing constraints 
 and picking the most natural way to follow through.
 
 Hey, let's make it so that classes can have several parameters! Um... 
 OK, that more or less makes sense. I can see uses for that.
 
 Hey, let's make it so a class instance can have one or more types 
 associated with it! Er... well, that seems straight forward enough. 
 Alright.
 
 Hey, let's make it so that class methods can have completely arbitrary 
 types! Wait, what the hell? How does *that* make sense?! o_O
 
 
Speaking as someone who, like you, came to the language recently and for
whom many of haskell's outer corners are still confusing, I should firstly
say that I can see where you're coming from but that it puzzles me as to why
you think things ought to be obvious or why, when something isn't obvious to
you, it must be useless? Could the answer be that it will take some time
before you understand the motivation for features that don't seem natural to
you? You might need some patience and study along with everything else, I
know I do (and people have been generous with links to work that explains
the motivation). I only say this because you seem, bizarrely, to be
suggesting that you could improve things by undoing the work of all these
scary people as you call them in another post, whilst admitting that you
don't understand it.



 Hey, let's make it so you can use a type variable on the RHS that 
 doesn't even appear on the LHS! Um... that's going to be tricky, but 
 sure, OK.
 
 Hey, let's make it so you can implement Prolog programs inside the type 
 system! Right, I'm getting my coat now... :-P
 
 In short, some of these relax restrictions in fairly obvious directions, 
 and others just seem downright bizzare.
 
 It helps if you can picture a matching explicitly-typed language.
   
 
 I don't really understand that statement.
 
 An idea you might find helps: what you're finding with algorithms, I find 
 with architecture when I have the extensions that let me type it.
   
 
 ...or that one...
 
 ___
 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/Memoization-tf3822500.html#a10829748
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] Arbitrary precision?

2007-05-06 Thread Jim Burton



Andrew Coppin wrote:
 
 ...
 
 Likewise...
 
 Oh, by the way, thanks for the extra syntax. It's really annoying having 
 to locate Notepad.exe on the start menu, type import Blah, save it as 
 Thing.hs, open Windoze Explorer, locate Thing.hs, and then 
 double-click it just so that I can try stuff out in GHCi...
 
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 

God that sounds painful. As well as reading about ghci [1] you might
consider Emacs and haskell-mode for a productive environment.  

[1] http://www.haskell.org/ghc/docs/6.4.2/html/users_guide/ghci.html

-- 
View this message in context: 
http://www.nabble.com/Arbitrary-precision--tf3700066.html#a10348633
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] Playing with GHC [was Arbitrary precision?]

2007-05-06 Thread Jim Burton



Andrew Coppin wrote:
 
 [...]
 Anyway... long ramble over... Emacs isn't my operating system of choice. 
 I prefer to use SciTE (which is *just* a text editor - as in, it doesn't 
 also come with an integrated toaster and alarm clock). One SciTE window 
 open, one command prompt pointing at the source folder... seems to work 
 fairly well. Would be nice if SciTE would colourise Haskell syntax, but 
 since Haskell is so absurdly hard to parse, I guess that's asking a lot.
 ;-)
 
 

Obviously you should stick with it if you're happy with it but It still
sounds pretty painful to me...using haskell-mode you have highlighted code
in one frame, ghci in another, resting the point over a function call
displays the type, the Declarations menu allows you to jump to a
function/datatype whatever, type C-L to execute the code in another frame
etc -- I'd say it was worth a look unless emacs brings you out in a rash.



 PS. What the heck email client puts URLs in as footnotes?
 
 ___
 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/Arbitrary-precision--tf3700066.html#a10349446
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] Intermediate Haskell Books?

2007-05-06 Thread Jim Burton



Adrian Neumann wrote:
 
 -BEGIN PGP SIGNED MESSAGE-
 Hash: RIPEMD160
 
 Are there any good books about intermediate to advanced Haskell? The
 descriptions here http://haskell.org/haskellwiki/Books_and_tutorials
 aren't very helpful.
 
 Adrian
 
 

I think The Fun of Programming fits that description. I don't suppose you'd
call it advanced (for that first decide which parts of the leading edge
you're interested in and see the resources referred to by others, esp.
reading recent papers) but it is a step or two on from the introductory
books and includes some really interesting code and ideas. 

-- 
View this message in context: 
http://www.nabble.com/Intermediate-Haskell-Books--tf3698891.html#a10349551
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] Parsec beginners problem

2007-04-28 Thread Jim Burton

Chris Kuklewicz wrote:

[snip]



There are other modules that come with Haskell than
Text.ParserCombinators.Parsec
such as
Text.ParserCombinators.ReadP

The solution with ReadP makes for a very short 'parse' function.  Note that
reader is built in a recursive manner.


module Morse where

import Control.Monad(guard)
import Text.ParserCombinators.ReadP

parse = map fst . readP_to_S reader
  where reader = done ++ choice (map pairToReader table)
done = look = guard . null  return []
pairToReader (s,c) = string s  fmap (c:) reader

table = (.-,'A'):
(-...,'B'):
(-.-.,'C'):
(-..,'D'):
(.,'E'):
(..-.,'F'):
(--.,'G'):
(,'H'):
(..,'I'):
(.---,'J'):
(-.-,'K'):
(.-..,'L'):
(--,'M'):
(-.,'N'):
(---,'O'):
(.--.,'P'):
(--.-,'Q'):
(.-.,'R'):
(...,'S'):
(-,'T'):
(..-,'U'):
(...-,'V'):
(.--,'W'):
(-..-,'X'):
(-.--,'Y'):
(--..,'Z'):
[]


The table is sorted which means the result of 'parse' is in sorted alphabetical
order.

It also does not check which are dictionary words, so it finds many solutions:

*Morse length $ parse ...---..--
5104

*Morse take 10 $  parse ...---..--
[EEAGAEEEA,EEAGAT,EEAGAEEIT,EEAGAEEU,EEAGAEIA,EEAGAEIET,EEAGAEST,EEAGAEV,EEAGAHT,EEAGAIEA]

Thanks Chris, that's a neat solution and an eye opener for me -- I need 
to investigate the Text package I think.

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


[Haskell-cafe] Parsec beginners problem

2007-04-27 Thread Jim Burton

I  have a couple of questions about my first use of Parsec, which is trying
to read morse code symbols from a string. I have a map of symbols:

import qualified Data.Map as M

morsemap = M.fromList [('A', .-)
   ...
   , ('Z', --..)]

a string to parse, like 

test = ...---..--

and a Parser to read a single morse letter:

morse1 :: GenParser Char st String
morseletter = try $ M.fold ((|) . string) (string ) morsemap

which I am hoping would be equivalent to

try (string .-)
| (string -.)
...etc
| string 

but I don't know what the base of the fold should be (string  is wrong I
suppose) - what is the unit of |? Is there a readymade combinator for
this?

It fails anyway:

*Main run morse1 test
parse error at (line 1, column 1):
unexpected .
expecting .-

I suppose this is because the strings I'm looking for overlap but I thought
the use of try..| would avoid this error...?

Thanks,
 
-- 
View this message in context: 
http://www.nabble.com/Parsec-beginners-problem-tf3657821.html#a10219707
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] Parsec beginners problem

2007-04-27 Thread Jim Burton



Dougal Stanton wrote:
 
 This may be relevant or not, but I thought morse required a delimiting
 character between letters, because otherwise the message was
 ambiguous? I seem to recall somewhere that Parsec didn't handle
 non-deterministic parsings very well (or at all).
 
 D.
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 

You could be right about delimiters, but handling the ambiguous instances is
the challenge in this case, which is a Ruby Quiz
[http://www.rubyquiz.com/quiz121.html] - I thought it would be a good use
for Parsec, and the user guide talks about try..| as the tool for it, as
in 

testOr2 =   try (string (a))
| string (b)

-- 
View this message in context: 
http://www.nabble.com/Parsec-beginners-problem-tf3657821.html#a10220154
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] Parsec beginners problem

2007-04-27 Thread Jim Burton



Jim Burton wrote:
 
 
 
 Dougal Stanton wrote:
 
 This may be relevant or not, but I thought morse required a delimiting
 character between letters, because otherwise the message was
 ambiguous? I seem to recall somewhere that Parsec didn't handle
 non-deterministic parsings very well (or at all).
 
 D.
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 
 
 You could be right about delimiters, but handling the ambiguous instances
 is the challenge in this case, which is a Ruby Quiz
 [http://www.rubyquiz.com/quiz121.html] - I thought it would be a good use
 for Parsec, and the user guide talks about try..| as the tool for it, as
 in 
 
 testOr2 =   try (string (a))
 | string (b)
 
 

After posting I realised the difference between parsing (a) | (b) and
parsing a | aa ... so Parsec doesn't do the latter well or at all?

-- 
View this message in context: 
http://www.nabble.com/Parsec-beginners-problem-tf3657821.html#a10220156
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] Why Perl is more learnable than Haskell

2007-04-11 Thread jim burton



kynn wrote:
 
 Perl is a large, ugly, messy language filled with quirks and
 eccentricities, while Haskell is an extremely elegant language whose
 design is guided by a few overriding ideas.  (Or so I'm told.)
 
 [snip]
 
 
May I ask why you want to learn it so much, if you find it so hard? I'm sure
most would disagree with me but maybe you'd be better off with perl for your
one liners and scripts if it serves your purpose well. You say that you've
heard Haskell is extremely elegant, but is that really the reason you want
to start using it as your general purpose and scripting language? I'm also
interested in it myself because of it's elegance, and in order to learn
different paradigms, to explore the strength of the type system etc etc, but
I'm not in a particular rush to be able to use it as the one true language
for scripting or web applications, or xyz, as quite a few people lately seem
to be asking about. Just curious.
-- 
View this message in context: 
http://www.nabble.com/Why-Perl-is-more-learnable-than-Haskell-tf3559193.html#a9946886
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] Monad/Functor Book

2007-03-30 Thread jim burton


Dave-86 wrote:
 
 Given the amount of material posted at haskell.org and elsewhere
 explaining IO, monads and functors, has anyone considered publishing
 a comprehensive book explaining those subjects?  (I am trying to
 read all the material online, but books are easier to read and don't
 require sitting in front of a computer to do so. Plus I can write in
 books :-). )
 
 Thanks, Dave Feustel
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 
Print out the wikibook [1]? IMO it has good coverage of Monads, more
detailed than any of the textbooks I've read, and leads into CT and advanced
topics that aren't really covered in any of the books (partly because a  lot
of it isn't Haskell 98 of course).

[1] http://en.wikibooks.org/wiki/Haskell 
-- 
View this message in context: 
http://www.nabble.com/Monad-Functor-Book-tf3474082.html#a9752877
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] Partial Evaluation

2007-03-21 Thread jim burton
I am reading Hudak's paper Modular Domain Specific Languages and Tools 
[1] and am confused by his use of the term `Partial Evaluation'. I 
understand it to mean supplying some but not all arguments to a 
function, e.g. (+3) but it seems to mean something else too. This is in 
the context of optimising performance:


We have used existing partial evaluation techniques to do 
this...Unfortunately, there does not currently exist a suitable, 
easy-to-use partial evaluator for Haskell. Our approach was to convert 
the Haskell program to Scheme, partially evaluate the Scheme program, 
and then translate back into Haskell.


What does P.E, mean here?

Thanks,


[1] Available 
http://wiki.ittc.ku.edu/lambda/Image:Hudak-Modular_Domain_Specific_Languages_and_Tools.pdf 


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


Re: [Haskell-cafe] Calendar Dates before the epoch

2007-02-14 Thread jim burton



Bjorn Bringert-2 wrote:
 
 
 Use the time package (Data.Time.*). time-1.0 is in GHC 6.6 extralibs, 
 and available from Hackage 
 (http://hackage.haskell.org/cgi-bin/hackage-scripts/package/time-1.0) 
 and the development version lives at
 http://darcs.haskell.org/packages/time/
 
 
Thanks Björn

Jim

-- 
View this message in context: 
http://www.nabble.com/Calendar-Dates-before-the-epoch-tf3221685.html#a8968473
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] Calendar Dates before the epoch

2007-02-13 Thread jim burton

It seems that CalendarTime is for dates since the epoch...what do I use to
handle dates before that? Sorry if this is an FAQ, I looked on the wiki and
tried to find MissingH since I thought it might be in there, but don't know
where to find it. I also found this from 2003 -
http://www.arcknowledge.com/gmane.comp.lang.haskell.libraries/2003-11/msg00019.html
- is the code in a library somewhere?

Thanks.
-- 
View this message in context: 
http://www.nabble.com/Calendar-Dates-before-the-epoch-tf3221685.html#a8947718
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] ghci stack overflow

2006-11-19 Thread jim burton

This code produces a stack overflow in ghci when I call `makeSpiral' with
large values, e.g. big enough to produce a 1001x1001 spiral. (makeSpiral
produces a list of lists which form a clockwise 'spiral', it's a puzzle from
mathschallenge.net.)

I'm sure there is a way to increase the stack space in ghc which I will look
into, but is there a way I could avoid the problem in the first place by
attacking the problem differently? Does stack space run out because the list
is an argument being passed around (1001x1001 versions of it)? If so would
the state monad help me?

data Dir = R | D | L | U deriving (Show, Eq, Enum) 
type Spiral = ([[Int]], Int, Dir) -- (rows, current row, next direction)

rows :: Spiral - [[Int]]
rows (rs, i, d) = rs
currentrow :: Spiral - Int
currentrow (rs, i, d) = i
nextdir :: Spiral - Dir
nextdir (rs, i, d) = d

getrow :: Int - [[Int]] - Maybe [Int]
getrow i sp = if i  0 || i = length sp then Nothing else Just (sp!!i)

ndir :: Dir - Dir 
ndir d = if d == U then R else succ d

newsp :: Spiral
newsp = ([[1]], 0, R)

makeSpiral :: Int - Spiral
makeSpiral i = makeSpiral' 2 newsp
where makeSpiral' j sp = if j  i 
 then sp 
 else makeSpiral' (j+1) (update j sp)

update :: Int - Spiral - Spiral
update i (sp, cr, d) = (sp', cr', d') 
where oldrow  = if (d == U  cr' == cr  cr == 0) || 
(d == D  cr' == length sp) 
then []
else fromJust $ getrow cr' sp
  cr'| d == L || d == R = cr
 | d == U = if cr == 0 then 0 else cr-1
 | otherwise = cr+1
  cr''   = if d == U  cr == 0 then -1 else cr'
  sp'= insertrow cr'' newrow sp 
  newrow = case d of 
  R - oldrow++[i]
  D - oldrow++[i] 
  L - i:oldrow 
  U - i:oldrow 
  d' | d == R || d == L = if length oldrow == maximum (map length
sp) 
  then ndir d 
  else d
 | d == U = if cr'' == -1 then ndir d else d
 | otherwise = if cr' == length sp then ndir d else d

insertrow :: Int - [Int] - [[Int]] - [[Int]]
insertrow i r rs = if i == -1 then r:rs else front++[r]++back 
where (front, rest) = splitAt i rs
  back = if null rest then [] else tail rest

printSpiral :: Spiral - IO ()
printSpiral (sp, i, d) = putStrLn (concat $ intersperse \n (map show sp))

sumdiags :: Spiral - Int
sumdiags (sp, i, d) = (sumdiags' 0 0 (+1)) + (sumdiags' 0 end (subtract 1))
- centre
where row1 = sp!!0
  end = length row1 - 1
  halfx = (length row1 `div` 2) 
  halfy = (length sp `div` 2) 
  centre = (sp!!halfy)!!halfx
  sumdiags' row col f = if row == length sp 
then 0
else (sp!!row)!!col + sumdiags' (row+1) (f
col) f
-- 
View this message in context: 
http://www.nabble.com/ghci-stack-overflow-tf2666036.html#a7435185
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] mapAccumL - find max in-sequence subsequence

2006-10-29 Thread jim burton



Sebastian Sylvan-2 wrote:
 
 I'm not sure I completely understand what you want, and if it needs to
 be cute (i.e. some clever one liner usage of a library function).
 But here's my get-the-job-done-solution (assuming I understood what
 you want):
 
 import Data.List
 import Data.Ord
 
 longestInSequence :: (Enum a) = [a] - Int
 longestInSequence = maximum . map (length . takeInSeq) . tails
 
 takeInSeq []  = []
 takeInSeq [x] = [x]
 takeInSeq (x:y:xs) | fromEnum (succ x) == fromEnum y = x : takeInSeq
 (y:xs)
| otherwise   = takeInSeq (x:xs)
 
 /S
 
Thanks, that's what I was looking for - and it doesn't need to be 'cute'!
-- 
View this message in context: 
http://www.nabble.com/mapAccumL---find-max-in-sequence-subsequence-tf2531704.html#a7059817
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] Solitaire cipher

2006-10-24 Thread jim burton

I'm a beginner having a go at implementing the Solitaire cipher
(http://www.rubyquiz.com/quiz1.html as mentioned in another post) and I'd be
really grateful if you could help me improve the code to be neater  use
more functions from the Prelude etc, or errors (eg at the moment I can't
work out why padding accumulates after encrypting, decrypting?)...Thanks. 

*Main decrypt $ encrypt haskell is better by miles
HASKE LLISB ETTER BYMIL ESAYP X 
*Main decrypt $ encrypt $ decrypt $ encrypt haskell is better by miles
HASKE LLISB ETTER BYMIL ESAYP X BFCRK X 
*Main 
---

import Char
import Random
import List
import Foreign
import Maybe

data Card = Clubs Int | Spades Int | Diamonds Int | Hearts Int | JokerA |
JokerB 
deriving (Show, Eq)
type Deck = [Card]
--cardval - clubs are face value, diamonds plus 13, and so on - Jokers are
both 53
cardval  :: Card - Int
cardval (Clubs i)= i
cardval (Diamonds i) = i+13
cardval (Hearts i)   = i+26
cardval (Spades i)   = i+39
cardval _= 53

isJoker:: Card - Bool
isJoker JokerA = True
isJoker JokerB = True
isJoker _  = False
--take a card to a letter 
card2char :: Card - Char
card2char c = case c of
  (Clubs i)- int2alpha $ cardval c --can case fall
through in haskell?
  (Diamonds i) - int2alpha $ cardval c
  (Hearts i)   - int2alpha $ (cardval c-26)
  (Spades i)   - int2alpha $ (cardval c-26)
  _- error (Can't make  ++ show c ++
into alpha)
--take a letter to int, A=1, Z=26
char2int :: Char - Int
char2int = (64 `subtract`) . (ord)
--take a letter to int, 1=A, Z=26
int2alpha :: Int - Char
int2alpha = (chr) . (+64)

splitAtMb n l = let p = splitAt n l
   in if null $ fst p
  then Nothing
  else Just p

in_fives l = foldr (\x y - x++ ++y) [] $ unfoldr (splitAtMb 5)
 (l ++ replicate (5 - length l `mod` 5) 'X') 

--get an ordered deck
newdeck :: Deck
newdeck = suit 'c' ++ suit 'd' ++ suit 'h' ++ suit 's' ++ JokerA : JokerB :
[]
where suit s = case s of
  'c' - [Clubs i | i - [1..13]]
  's' - [Spades i | i - [1..13]]
  'd' - [Diamonds i | i - [1..13]]
  'h' - [Hearts i | i - [1..13]]

--key the deck ready to provide a keystream - move JokerA down one place,
--JokerB down 2 places, perform a triplecut then a countcut
keydeck :: Deck - Deck
keydeck = countcut. triplecut . (movedown JokerB) . (movedown JokerB) .
(movedown JokerA)

--bump a card down by one place in a deck, treating the deck as circular so
if the card is
-- last in the deck it becomes 2nd to front not 1st
movedown :: Eq a = a - [a] - [a]
movedown c d = if c == last d
   then head d : c : init (tail d)
   else top ++ bot!!1 : c : (tail (tail bot))
   where splt = splitAt (locate c d) d
 top = fst splt
 bot = snd splt
--substitute the cards above the first joker for those below the 2nd one
triplecut :: Deck - Deck 
triplecut d = afterLastJoker d ++ center d ++ beforeFirstJoker d
  where beforeFirstJoker = takeWhile (not . isJoker)
afterLastJoker = reverse . beforeFirstJoker . reverse 
center = reverse . dropWhile (not . isJoker) . reverse .
dropWhile (not . isJoker)

--get the value of the last card and move that many cards from the top of
deck to above the last card
countcut :: Deck - Deck
countcut d = init (drop n d) ++ take n d ++ [last d]
 where n = cardval (last d)

--key the deck, read the value of the top card as n, add the nth card to
stream, repeat
keystream :: Deck - String
keystream d = if isJoker c then keystream d' else card2char c : keystream d'
  where d' = keydeck d
c  = d'!!(cardval $ d'!!0)

locate :: Eq a = a - [a] - Int
locate x xs = fromJust (elemIndex x xs)

clean :: String - String
clean = map toUpper . filter isAlpha

encrypt, decrypt :: String - String
--encrypt a string using an unshuffled deck to start
encrypt = process (\x y - max26 (x+y))
where max26 x = if x  26 then x-26 else x
--decrypt a string using an unshuffled deck to start
decrypt = process (\x y - if x = y then (x+26)-y else x-y)

process :: (Int - Int - Int) - String - String
process f s = in_fives $ map int2alpha $ zipWith f ints1 ints2
where str1  = clean s
  str2  = take (length str1) (keystream newdeck)
  ints1 = map char2int str1
  ints2 = map char2int str2

-- 
View this message in context: 
http://www.nabble.com/Solitaire-cipher-tf2500700.html#a6971077
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Haskell beginner questions

2006-10-24 Thread jim burton



Cybertronic wrote:
 
 Hi all, I'm pretty much new to Haskell however I'm stuck on something
 which is that I'm trying to create a function called display where I type
 in a DVD name, e.g. dvd1, it returns d (String) and the multiplication of
 q (Int) and i (Double)
 
 Here's what I've done so far:
 
 type Film = (Int,String,Int,Double)
 
 dvd1 :: Film
 dvd1 = (1, Space, 5, 9.99)
 
 display :: Product - String
 display (c,d,q,i) = d
 
 My display function only shows the string but unfortunately I'm stuck on
 how to get the display function to multiply q (Int) and i (Double)
 together and display it next to d.
 
 Can someone help me out please? :)
 

I'd recommend a tutorial like
http://www.cs.utah.edu/~hal/docs/daume02yaht.pdf 

 display :: Film - String
 display (c,d,q,i) = d ++   ++ show (fromIntegral q * i)

q needs to be converted first and show will convert the result to a string. 

-- 
View this message in context: 
http://www.nabble.com/Haskell-beginner-questions-tf2500050.html#a6971248
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] Solitaire cipher

2006-10-24 Thread jim burton



Chris Kuklewicz wrote:
 
 There are several problems with the behavior:
 
 *Main encrypt 
 X 
 *Main decrypt $ encrypt 
 TANZP X 
 
 So fixing this case would be the first thing to do, followed by:
 
 *Main encrypt hello
 LBVJW X 
 *Main decrypt $ encrypt hello
 HELLO YFRTQ X 
 
 

Thanks a lot, I think these are all related...some changes

in_fives l = trim $ foldr (\x y - x++ ++y) [] $ unfoldr (splitAtMb 5)
 (l ++ replicate n 'X') 
 where n = if m5 == 0 then 0 else 5 - m5
   m5 = length l `mod` 5

trim :: String - String
trim = reverse . dropWhile isSpace . reverse . dropWhile isSpace

process :: (Int - Int - Int) - String - String
process f s = if null str1 then  else in_fives $ map int2alpha $ zipWith f
ints1 ints2
where str1  = trim $ clean s
  str2  = take (length str1) (keystream newdeck)
  ints1 = map char2int str1
  ints2 = map char2int str2

*Main decrypt $ encrypt $ decrypt $ encrypt hello
HELLO
*Main decrypt $ encrypt $ decrypt $ encrypt haskell is miles better
HASKE LLISM ILESB ETTER
*Main 

-- 
View this message in context: 
http://www.nabble.com/Solitaire-cipher-tf2500700.html#a6971503
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] Solitaire cipher

2006-10-24 Thread jim burton


Jón Fairbairn-2 wrote:
 
 jim burton [EMAIL PROTECTED] writes:
 
 In addition to Chris's comments, here are some more:
 [snip]
 

Thanks for your comments Jon. I thought about making Cards an instance of
Enum but didn't realise how helpful it would be in various places.

I will use the shorter version of your function - I need to get a chance to
think about how it works first to be honest.

Haven't noticed divMod before - handy!

-- 
View this message in context: 
http://www.nabble.com/Solitaire-cipher-tf2500700.html#a6979284
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] split string into n parts

2006-10-23 Thread jim burton

I want to split a string into 5 parts of equal length, with the last fifth
padded if necessary, but can't get it right - here's what I've got - 

 fifths :: String - String
 fifths s = fifths'  0 s
 where l = (length s) `div` 5
   fifths' xs c [] = xs ++ (replicate (l-c) 'X')
   fifths' xs c (y:ys) = if c == l 
 then fifths' (xs++[' ',y]) 0
 ys 
 else fifths' (xs++[y]) (c+1)
 ys 

which, apart from surely being uglier than need be, doesn't work:

*Main fifths IDOLIKETOBEBESIDETHESEASIDE
IDOLI KETOBE BESIDE THESEA SIDEXX
*Main fifths 12345
1 23 45

Any thoughts? Thanks! This isn't homework BTW, I'm having a go at the ruby
quiz puzzles in haskell, which seems to be a nice way to learn.
-- 
View this message in context: 
http://www.nabble.com/split-string-into-n-parts-tf2496941.html#a6960346
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] split string into n parts

2006-10-23 Thread jim burton



Paul Brown-4 wrote:
 
 Cool idea!  Can you post a link for the puzzles?
 
Thankyou! It's http://www.rubyquiz.com - They are mostly well suited to
haskell, lot of mazes etc. I've done 5 or 6 with varying degrees of success
but have learned a lot. This thing about strings in fifths is from #1, the
solitaire cipher.

 
 As for this one, don't you want the first multiple of five larger than
 the length of the string?  You should be able to make things simpler
 if you auto-pad the string from the get-go (forgive any syntax errors,
 as I'm just composing in a browser here...):
 
 [snip]
 
Good plan! I will play with that.
-- 
View this message in context: 
http://www.nabble.com/split-string-into-n-parts-tf2496941.html#a6961186
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] split string into n parts

2006-10-23 Thread jim burton



Mark T.B. Carroll-2 wrote:
 
 
 FWIW this unholy thing works for me,
 
 fifths :: String - String
 
 fifths = splitIntoN 5
 
 [snip]
 
 
Thanks Mark.
-- 
View this message in context: 
http://www.nabble.com/split-string-into-n-parts-tf2496941.html#a6961461
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] split string into n parts

2006-10-23 Thread jim burton



Jón Fairbairn-2 wrote:
 
 
 At a quick glance I can't see which bit needs it. The only
 mention of five is where it asks to split the string into
 groups of five characters (not into five equal parts),
 padded with Xs.
 
Oh dear, you're right. Sorry, I read in a rush. Thanks for the solution too.


Jón Fairbairn-2 wrote:
 
 You can do that like this:
 
splitAtMb n l = let p = splitAt n l
in if null $ fst p
   then Nothing
   else Just p
 
in_fives l = unfoldr (splitAtMb 5)
 (l ++ replicate (length l `mod` 5) 'X')
 
 To break a string into five equal parts with the last padded
 with Xs, try this:
 
fifths l = let len = length l
   part_length = (len+4)`div`5
   pad_length = 5*part_length - len
   in unfoldr (splitAtMb part_length)
  (l ++ replicate pad_length 'X')
 
 I haven't checked these at all carefully, but at least they
 illustrate the use of unfoldr.  [aside: One might argue that
 the prelude ought to provide splitAtMb rather than splitAt.]
 
 -- 
 Jón Fairbairn [EMAIL PROTECTED]
 
 ___
 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/split-string-into-n-parts-tf2496941.html#a6961825
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] split string into n parts

2006-10-23 Thread jim burton

tweak to in_fives

 in_fives l = unfoldr (splitAtMb 5)
(l ++ replicate (5 - length l `mod` 5) 'X')

-- 
View this message in context: 
http://www.nabble.com/split-string-into-n-parts-tf2496941.html#a6961912
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