[Haskell-cafe] Debugging a RecSel Error

2009-04-17 Thread Gü?nther Schmidt

Hi all,

I'm trying to find the spot in my source code that triggered a RecSel 
Exception (No match in record selector


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


Re: [Haskell-cafe] Synchronising cabal package version with self-reported version

2009-04-17 Thread Denis Bueno
On Fri, Apr 17, 2009 at 20:41, Don Stewart d...@galois.com wrote:
 dbueno:
 Hi all,

 In a command-line app of mine I want to have a --version flag, like
 many GNU apps do to report their version.  The only way I know to
 provide the version number is to hardcode it in the source code
 somewhere.  That means I have the version number in two places: the
 .cabal file and the source code.  I just know that one day they'll get
 unsynchronised, and --version will be wrong.

 Is there any way to put the version number in _one_ place, and have
 both the .cabal and source refer to it?  Or even any easier way to
 synchronise both version numbers?

 Yes, cabal provides support for this. Here's how we do that in xmonad.

 In your program, import the magic module Paths_$progname:

    import Paths_xmonad (version)

        [--version]         - putStrLn (xmonad  ++ showVersion version)

 which provides many fields from the .cabal file used to compile the
 program.

Awesome!  Thanks.  This is exactly what I was hoping for.
  Denis
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Computing a sorted list of products lazily

2009-04-17 Thread wren ng thornton

Jason Dagit wrote:

Hello,

A colleague of mine recently asked if I knew of a lazy way to solve
the following problem:
Given two sets of sorted floating point numbers, can we lazily
generate a sorted list of the products from their Cartesian product?

The algorithm should return the same result as:
sortProduct a b = sort [ x * y | x - a, y - b ]

But, my friend is not satisfied with the strictness of sort.  In
particular, he doesn't want to have to hold the whole list in memory
to sort it.  He would like to compute the results one product at a
time and in the correct order.


The algorithm you're looking for is called (lazy) cube pruning and is 
quite common in machine translation. If you're willing to slog through 
MT papers, this one[1] gives a decent introduction as I recall. The 
algorithm works for any monotone combination function.


The basic idea is to do a frontier search on the cartesian grid. We know 
a priori that the first elements of each list will give the best 
combination value. We return that value as the first of our new list, 
and mark it off on the grid (not really), we then look at the next 
element for each list and compute the combination values for each of the 
new fringe cells, and store them in a heap. Pick the best value out of 
the heap and return it as the next element of the list, 'mark it off' on 
the grid and explore the new fringe.


Because the combination function is monotone, this search strategy 
guarantees you'll encounter every combination values in the right order 
to return them with minimal delay. The only downside is that you need to 
maintain the heap of seen values that aren't ready to be returned yet 
(which can grow quite large in the worst case). For MT systems where 
this can really be a problem, the cube search strategy is often 
integrated with beam search (i.e. if the heap grows larger than some 
size limit then the worst values start dropping out of the bottom)--- 
hence the name cube *pruning*.



If you don't feel encumbered by the LGPL, we have a Java implementation 
of the full algorithm already. Your use case is much simpler than the 
variant necessary for MT, but the reference implementation can be quite 
helpful. Feel free to contact me off-list if you're interested, I can 
point you to our repository and where the algorithm is in the morass of 
code.



[1] http://www.cis.upenn.edu/~lhuang3/acl-cube.pdf

--
Live well,
~wren
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] wxHaskell not in scope

2009-04-17 Thread minh thu
Hi,
you can use http://hpaste.org/ to overcome this problem.

Cheers,
Thu

2009/4/17 Tsunkiet Man temp.t...@gmail.com:
 PS: if the indents are wrong, that's because of gmail copy and past, Im so
 sorry.

 2009/4/17 Tsunkiet Man temp.t...@gmail.com

 Hello,

 what you suggested worked! Im very happy with it. However another error
 suddenly came up. It sais the last statement in a 'do' must be an
 expression, he is refering to line 41:45

 I change my code to this:

 on (menu exit) := close f,
 on (menu open) := onOpen f dt vFile ]

 return ()

 where
 onOpen :: Frame a - staticText c - Var b - IO ()
 onOpen frame stat var = do   file - fileOpenDialog frame
 False True Open File [(PGM bestanden (*.pgm),[*.pgm]),(Alle bestanden
 (*.*),[*.*])]  
 case file of
 Nothing -  return ()
 Just file -set stat [text
 := HELLO]
 return ()

 As far as I can tell, if the file is nothing it will return something of
 IO () and if the file is something it will return something of IO (). So
 that error is kind of strange in my opinion. Do you know what caused it?

 Thanks for your help!

 2009/4/17 Lennart Augustsson lenn...@augustsson.net

 Take a look at the syntax for 'let' inside a 'do'.

 On Fri, Apr 17, 2009 at 12:57 AM, Tsunkiet Man temp.t...@gmail.com
 wrote:
  PS: a small note, sorry for multiple mails.
 
  After doing the let ... in function it did not work. =( It gave the
  error
  that 'do' has to end with some result. I did:
 
  do let the function in all the code that was behind the do
 
  and it still didn't work =(. I'm doing something wrong I think.
 
  Thanks for your help.
 
  2009/4/17 Tsunkiet Man temp.t...@gmail.com
 
  Thank you for your response, however if I can't do that, why can the
  example of wxHaskell do that?
 
  I refer to the following code inside
  http://darcs.haskell.org/wxhaskell/samples/wx/ (ImageViewer.hs)
 
  Line 99 untill 110
 
  openImage sw vbitmap mclose status fname
= do -- load the new bitmap
 bm - bitmapCreateFromFile fname  -- can fail with
  exception
 closeImage vbitmap
 set vbitmap [value := Just bm]
 set mclose [enabled := True]
 set status [text := fname]
 -- reset the scrollbars
 bmsize - get bm size
 set sw [virtualSize := bmsize]
 repaint sw
 `catch` \err - repaint sw
 
  if I'm correct the openImage is also defined in the where clause.
  Therefor
  by what I think it should not be possible, but it is.
 
  Thanks for everything.
 
 
 
 
  2009/4/17 Lennart Augustsson lenn...@augustsson.net
 
  Variables bound in the do block are not in scope in the where.
  Use a let inside the do for onOpen instead.
 
  On Thu, Apr 16, 2009 at 11:53 PM, Tsunkiet Man temp.t...@gmail.com
  wrote:
   Hello,
  
   I'm trying to create a GUI by using wxHaskell. However I get the
   weird
   error
   message of Not in scope dt, well so I sorted them so that my so
   called
   dt was in scope, however it failed. Can someone please tell me
   how I
   can
   solve this error?
  
  ... A lot of code that is not relevant in my opinion, if
   I'm
   wrong please correct me and I will post my full code
  
   --Debug text --
   dt - staticText f [text := Hello world!]
  
   imagePanel - panel f [position := Point 2 2,
   clientSize :=
   Size
   100 100, tooltip := This is a drawPanel, bgcolor := rgb 255 255
   255]
   set f [ clientSize := Size 700 500,
   menuBar := [mFile, mHelp],
   visible := True,
   on (menu exit) := close f,
   on (menu open) := onOpen f vFile ]
  
  
   return ()
  
   where
   onOpen :: Frame a - Var b - IO ()
   onOpen frame var = do   file - fileOpenDialog
   frame
   False
   True Open File [(PGM bestanden (*.pgm),[*.pgm]),(Alle
   bestanden
   (*.*),[*.*])]  
   case file of
   Nothing -  return
   ()
   Just file -set dt
   [text :=
   HELLO]
   return
   ()
  
   Thank you for your help, I really owe haskell-cafe.
  
   Greetings Tsunkiet Man
   ___
   Haskell-Cafe mailing list
   Haskell-Cafe@haskell.org
   http://www.haskell.org/mailman/listinfo/haskell-cafe
  
  
 
 
 



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

Re: [Haskell-cafe] Parsec question

2009-04-17 Thread minh thu
2009/4/17 Michael P Mossey m...@alumni.caltech.edu:
 I want to write a parser that can read a file with this format: the file has
 sections which are demarcated by keywords. Keywords always begin with two
 forward slashes and consist of letters, digits, and underscore. The text can
 be anything, including special characters. For instance:


 //keyword some text
 and more text //another_keyword and) some { more text
 //ya_keyword $$
 -- text


 I'm not sure how to write a parser that considers anything but a double
 slash to be a valid part of the text.

Maybe you can use a combination of 'many', 'noneOf' or 'manyTill' ?

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


[Haskell-cafe] Re: O LANGUAGE DESIGNER, REMEMBER THE POOR USER

2009-04-17 Thread Benjamin L . Russell
On Thu, 16 Apr 2009 19:04:43 -0500, Matt Morrow moonpa...@gmail.com
wrote:

This is interesting (and from 1990):

http://groups.google.co.uk/group/comp.lang.functional/msg/655bb7bbd0fd8586

(Not sure if this is well-known. It seems like it either is, or it should
be. Either way, I just stumbled across it.)

Regarding the following quoted portion:

USERS OF FUNCTIONAL LANGUAGES WILL HAVE SOME STRONG PRECONCEPTIONS ABOUT HOW
COMPUTATIONS ARE EXPRESSED.

... Since, if a functional language is to be successful, the great
body of its users can be expected to be drawn from the millions who have some
expierience of Ada, C or Pascal, the conventions pertaining in those languages
should have weight in the forms chosen for any functional language where they
do not conflict with the essential attributes of the functional language.

Sorry, but I do not agree with this view.

Essentially, this means that new functional languages should in some
way syntactically resemble Ada, C or Pascal.  However, many newcomers
to such functional languages as Haskell come from other languages (I
myself come from Scheme and T), and requiring Haskell to resemble Ada,
C or Pascal would risk alienating such other users.

Besides, regarding the premise of if a functional language is to be
succesful, why is it so important that a functional language ... be
successful in the first place?  Both Simon Peyton Jones and Alan
Perlis have disagreed on this issue.

According to [2] (see
http://research.microsoft.com/en-us/um/people/simonpj/papers/history-of-haskell/history.pdf)
(see page 10), there are definite reasons for striving to avoid
success at all costs, as follows:

The fact that Haskell has, thus far, managed the tension between
these two strands of development [as a mature language, and as a 
laboratory in which to explore advanced language design ideas] is 
perhaps due to an accidental virtue: Haskell has not become too 
successful. The trouble with runaway success, such as that of Java, 
is that you get too many users, and the language becomes bogged 
down in standards, user groups, and legacy issues. In contrast, the 
Haskell community is small enough, and agile enough, that it usually 
not only absorbs language changes but positively welcomes them: 
it’s like throwing red meat to hyenas.

Furthermore, to quote [1] below (see the dedication of SICP at
http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-3.html), isn't
our role supposed to be to keep fun in computing?

``I think that it's extraordinarily important that we in computer science 
keep fun in computing. When it started out, it was an awful lot of fun. Of 
course, the paying customers got shafted every now and then, and after 
a while we began to take their complaints seriously. We began to feel as if 
we really were responsible for the successful, error-free perfect use of 
these machines. I don't think we are. I think we're responsible for stretching 
them, setting them off in new directions, and keeping fun in the house. I 
hope the field of computer science never loses its sense of fun. Above all, I 
hope we don't become missionaries. Don't feel as if you're Bible salesmen. 
The world has too many of those already. What you know about computing 
other people will learn. Don't feel as if the key to successful computing is 
only 
in your hands. What's in your hands, I think and hope, is intelligence: the 
ability to see the machine as more than when you were first led up to it, that 
you can make it more.''

Alan J. Perlis (April 1, 1922-February 7, 1990)

I had always thought that part of the advantage of Haskell was the
ability of being agile enough to experiment.  Robbing Haskell of that
advantage would seem to kick the fun out of the house.

-- Benjamin L. Russell

References

[1] Abelson, Harold and Sussman, Gerald Jay with Sussman, Julie.
_Structure and Interpretation of Computer Programs, Second Edition._
Cambridge, MA: The MIT Press and New York: McGraw-Hill, 1996.
http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-3.html

[2] Hudak, Paul, Hughes, John, Peyton Jones, Simon, and Wadler,
Philip. A History of Haskell: Being Lazy With Class. San Diego,
California: _The Third ACM SIGPLAN History of Programming Languages
Conference (HOPL-III)_ (2007): 12-1 - 12-55, 2007.
http://research.microsoft.com/en-us/um/people/simonpj/papers/history-of-haskell/history.pdf
-- 
Benjamin L. Russell  /   DekuDekuplex at Yahoo dot com
http://dekudekuplex.wordpress.com/
Translator/Interpreter / Mobile:  +011 81 80-3603-6725
Furuike ya, kawazu tobikomu mizu no oto. 
-- Matsuo Basho^ 

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


Re: [Haskell-cafe] Parsec question

2009-04-17 Thread Michael Mossey

Here's what I've got so far.

-- Text is considered everything up to //. However, the problem
-- is that this consumes the //.
parseText = manyTill anyChar (try (string //))

-- Because the // is already consumed, parseKeyword just grabs
-- the available letters.
parseKeyword :: Parser String
parseKeyword = many1 letter




-- Test function.
parseSome = do t1 - parseText
   k1 - parseKeyword
   t2 - parseText
   return (t1,k1,t2)

On some text//keyword more text// this gives

(some text,keyword, more text)

On some text//keyword more text

this gives the error expecting //

I wonder how I can get the manyTill to be happy with eof before finding the //? 
I tried

parseText = manyTill anyChar (try (string //) | eof)

but got a type error.


minh thu wrote:

2009/4/17 Michael P Mossey m...@alumni.caltech.edu:

I want to write a parser that can read a file with this format: the file has
sections which are demarcated by keywords. Keywords always begin with two
forward slashes and consist of letters, digits, and underscore. The text can
be anything, including special characters. For instance:


//keyword some text
and more text //another_keyword and) some { more text
//ya_keyword $$
-- text


I'm not sure how to write a parser that considers anything but a double
slash to be a valid part of the text.


Maybe you can use a combination of 'many', 'noneOf' or 'manyTill' ?

Cheers,
Thu

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


Re: [Haskell-cafe] RE: [Announce] primes

2009-04-17 Thread Sebastian Fischer
Oh, I just remembered, I'm using ghci. I'll bet that's why I'm so  
slow.


I also did, but after installing the package using cabal. IIRC, cabal  
compiles with -O2 by default. But if you downloaded the tarball and  
then loaded the module in ghci without installing it, this is probably  
the reason for the slow response.


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


Re: [Haskell-cafe] Parsec question

2009-04-17 Thread minh thu
You can use 'notFollowedBy' (probably with 'many1' and 'try').
Something like (untested):

notFollowedBy (try $ string //)

Thu

2009/4/17 Michael Mossey m...@alumni.caltech.edu:
 Here's what I've got so far.

 -- Text is considered everything up to //. However, the problem
 -- is that this consumes the //.
 parseText = manyTill anyChar (try (string //))

 -- Because the // is already consumed, parseKeyword just grabs
 -- the available letters.
 parseKeyword :: Parser String
 parseKeyword = many1 letter




 -- Test function.
 parseSome = do t1 - parseText
   k1 - parseKeyword
   t2 - parseText
   return (t1,k1,t2)

 On some text//keyword more text// this gives

 (some text,keyword, more text)

 On some text//keyword more text

 this gives the error expecting //

 I wonder how I can get the manyTill to be happy with eof before finding the
 //? I tried

 parseText = manyTill anyChar (try (string //) | eof)

 but got a type error.


 minh thu wrote:

 2009/4/17 Michael P Mossey m...@alumni.caltech.edu:

 I want to write a parser that can read a file with this format: the file
 has
 sections which are demarcated by keywords. Keywords always begin with two
 forward slashes and consist of letters, digits, and underscore. The text
 can
 be anything, including special characters. For instance:


 //keyword some text
 and more text //another_keyword and) some { more text
 //ya_keyword $$
 -- text


 I'm not sure how to write a parser that considers anything but a double
 slash to be a valid part of the text.

 Maybe you can use a combination of 'many', 'noneOf' or 'manyTill' ?

 Cheers,
 Thu

 ___
 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] Parsec question

2009-04-17 Thread Michael Mossey

My confusion is that text is by definition followed by // or eof.


minh thu wrote:

You can use 'notFollowedBy' (probably with 'many1' and 'try').
Something like (untested):

notFollowedBy (try $ string //)

Thu

2009/4/17 Michael Mossey m...@alumni.caltech.edu:

Here's what I've got so far.

-- Text is considered everything up to //. However, the problem
-- is that this consumes the //.
parseText = manyTill anyChar (try (string //))

-- Because the // is already consumed, parseKeyword just grabs
-- the available letters.
parseKeyword :: Parser String
parseKeyword = many1 letter




-- Test function.
parseSome = do t1 - parseText
  k1 - parseKeyword
  t2 - parseText
  return (t1,k1,t2)

On some text//keyword more text// this gives

(some text,keyword, more text)

On some text//keyword more text

this gives the error expecting //

I wonder how I can get the manyTill to be happy with eof before finding the
//? I tried

parseText = manyTill anyChar (try (string //) | eof)

but got a type error.


minh thu wrote:

2009/4/17 Michael P Mossey m...@alumni.caltech.edu:

I want to write a parser that can read a file with this format: the file
has
sections which are demarcated by keywords. Keywords always begin with two
forward slashes and consist of letters, digits, and underscore. The text
can
be anything, including special characters. For instance:


//keyword some text
and more text //another_keyword and) some { more text
//ya_keyword $$
-- text


I'm not sure how to write a parser that considers anything but a double
slash to be a valid part of the text.

Maybe you can use a combination of 'many', 'noneOf' or 'manyTill' ?

Cheers,
Thu

___
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] Parsec question

2009-04-17 Thread Jason Dusek
2009/04/17 minh thu not...@gmail.com:
 2009/04/17 Michael Mossey m...@alumni.caltech.edu:
 I wonder how I can get the manyTill to be happy with eof
 before finding the //? I tried

 parseText = manyTill anyChar (try (string //) | eof)

 but got a type error.

 You can use 'notFollowedBy' [...]

  You get a type error because `string //` parses to a
  `String` while `eof` parses to a `()`. Instead you might use:

parseText = manyTill anyChar (try (string //  return ()) | eof)

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


Re: [Haskell-cafe] wxHaskell not in scope

2009-04-17 Thread Daniel Fischer
Am Freitag 17 April 2009 01:37:25 schrieb Tsunkiet Man:
 Hello,

 what you suggested worked! Im very happy with it. However another error
 suddenly came up. It sais the last statement in a 'do' must be an
 expression, he is refering to line 41:45

 I change my code to this:

 on (menu exit) := close f,
 on (menu open) := onOpen f dt vFile ]

 return ()

 where
 onOpen :: Frame a - staticText c - Var b - IO ()
 onOpen frame stat var = do   file - fileOpenDialog frame
 False True Open File [(PGM bestanden (*.pgm),[*.pgm]),(Alle
 bestanden (*.*),[*.*])]  
 case file of
 Nothing -  return ()
 Just file -set stat [text

 := HELLO]

 return ()


In the Just file case, you want to have two IO-actions. If you don't use 
(=) or () 
to chain them together, you must put them in a do-block, so

case file of
  Nothing - return ()
  Just file - do set stat [text := HELLO]
  return ()

But I think you can omit the return () in that branch anyway, set foo bar 
should have the 
correct type already.


 As far as I can tell, if the file is nothing it will return something of IO
 () and if the file is something it will return something of IO (). So that
 error is kind of strange in my opinion. Do you know what caused it?

 Thanks for your help!


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


[Haskell-cafe] Haskell Weekly News: Issue 114 - April 17, 2009

2009-04-17 Thread Brent Yorgey
---
Haskell Weekly News
http://sequence.complete.org/hwn/20090417
Issue 114 - April 17, 2009
---

   Welcome to issue 114 of HWN, a newsletter covering developments in the
   [1]Haskell community.

   The [2]5th Haskell Hackathon is underway in Utrecht! Happy Haskell
   hacking! An early HWN this week since I will be traveling this weekend
   (but not, unfortunately, to the Hackathon).

Announcements

   Reminder: Haskell Communities and Activities Report. Janis Voigtlaender
   [3]reminded everyone that the deadline for the [4]May 2009 edition of
   the Haskell Communities and Activities Report is only two weeks away.
   If you haven't already, please write an entry for your new project, or
   update your old entry.

   primes. Sebastian Fischer [5]announced the release of the [6]primes
   package, which implements lazy wheel sieves for efficient, purely
   functional generation of prime numbers in Haskell.

   level-monad-0.3. Sebastian Fischer [7]announced version 0.3 of the
   package [8]level-monad, which implements breadth-first search directly
   as an instance of MonadPlus (without using an intermediate tree
   representation). Version 0.3 adds a MonadPlus instance for iterative
   deepening inspired by Michael Spivey's paper on [9]Algebras for
   combinatorial search.

   hgettext 0.1.10. Vasyl Pasternak [10]announced a new release of the
   [11]hgettext package, which now has bindings to all gettext functions.

   Haskell logo in TeX. Philip Hölzenspies [12]announced a version of the
   new [13]Haskell logo design prepared using TikZ, for inclusion in LaTeX
   documents.

   The Monad.Reader (14) - Call for copy. Wouter Swierstra [14]issued a
   call for copy for Issue 14 of [15]The Monad.Reader. The deadline for
   submissions is May 15, 2009. Let Wouter know if you intend to submit
   something -- the sooner, the better.

   time 1.1.2.4. Ashley Yakeley [16]announced the release of [17]time
   1.1.2.4, which should now compile on Windows.

Discussion

   Code Golf. Sebastian Fischer [18]started a lively round of code golf
   with his code for list diagonalization.

   Converting IO [XmlTree] to [XmlTree]. rodrigo.bonifacio [19]asked how
   to convert an IO [XmlTree] into an [XmlTree], leading to a discussion of
   Haskell pedagogy.

Blog noise

   [21]Haskell news from the [22]blogosphere.
 * Roman Cheplyaka: [23]Fun in Utrecht.
 * Roman Cheplyaka: [24]Utrecht: first impressions.
 *  Daniel van den Eijkel: [25]Hommage: Haskell Offline Music
   Manipulation And Generation EDSL.
 *  Brandon Simmons: [26]Some initial tests of Tries.
 * Christopher Lane Hinson: [27]Trends in Profiling Haskell.
 *  Larry O'Brien: [28]Windows  .NET Watch: Haskell: It's like
   Klingon, but with math!.
 * Sean Escriva: [29]Why Haskell is a joy to learn.
 * GHC / OpenSPARC Project: [30]Instruction counts on x86 vs SPARC.
 * Sebastian Fischer: [31]Barefaced pilferage of monadic bind.
 * Benjamin L. Russell: [32]Climbing the Towers of Hanoi with
   Haskell-style Curry from a Monadic Container (While Sparing the
   Sugar!).

Quotes of the Week

 * Gracenotes: And then the type system goes all crazy and demands
   that x and 1 are both Word32s!
 * mauke: data What a = No; instance Monad What where { return _ = No;
   No = _ = No }
 * pumpkin: makes the next internet hit video, 2 natural
   transformations, 1 functor
 * mmorrow: a functor is like an analogy between two analogies
 * FliPPeh: @faq Can Conficker be rewritten in Haskell? lambdabot
   no location info: parse error on input `:'
 * HairyDude: The Haskell Type System is a Harsh Mistress.. there
   ain't no such thing as a free theorem.
 * LeCamarade: Now, let's say the set is {Haskell, SML, Ruby,
   Tomatoes, Human, Cabbage, Noise, IRC}.
 * pjdelport: YO DAWG I HERD YOU LIKE CARS SO WE PUT A PAIR IN YO CAR
   SO YOU CAN CAR WHILE YOU CAR
 * Babelfish: And there you travel: a beam tracer! Naturally, there
   are many things that ought to be amend.

About the Haskell Weekly News

   New editions are posted to [33]the Haskell mailing list as well as to
   [34]the Haskell Sequence and [35]Planet Haskell. [36]RSS is also
   available, and headlines appear on [37]haskell.org.

   To help create new editions of this newsletter, please see the
   information on [38]how to contribute. Send stories to byorgey at cis
   dot upenn dot edu. The darcs repository is available at darcs get
   [39]http://code.haskell.org/~byorgey/code/hwn/ .

References

   1. http://haskell.org/
   2. http://haskell.org/haskellwiki/Hac5
   3. http://article.gmane.org/gmane.comp.lang.haskell.cafe/57075
   4. http://www.haskell.org/pipermail/haskell/2009-April/021180.html
   5. http://article.gmane.org/gmane.comp.lang.haskell.cafe/57042

Re: [Haskell-cafe] RE: [Announce] primes

2009-04-17 Thread michael rice
You're right. Since I'm not familiar with Cabal, I didn't use it. Is there a 
good tutorial? Docs?

Also, I'm running a 32-bit Linux OS. Does one get a significant speed increase 
by
switching to a 64-bit OS?

Thanks for the feedback.

Michael

--- On Fri, 4/17/09, Sebastian Fischer s...@informatik.uni-kiel.de wrote:

From: Sebastian Fischer s...@informatik.uni-kiel.de
Subject: Re: [Haskell-cafe] RE: [Announce] primes
To: Haskell Cafe mailing list haskell-cafe@haskell.org
Date: Friday, April 17, 2009, 4:03 AM

Oh, I just remembered, I'm using ghci. I'll bet that's why I'm so slow.
I also did, but after installing the package using cabal. IIRC, cabal compiles 
with -O2 by default. But if you downloaded the tarball and then loaded the 
module in ghci without installing it, this is probably the reason for the slow 
response.
Cheers,Sebastian
-Inline Attachment Follows-

___
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] types and braces

2009-04-17 Thread Josef Svenningsson
Conor,

I'd like to point out a few things that may help you on the way.

On Wed, Apr 15, 2009 at 8:58 PM, Conor McBride
co...@strictlypositive.org wrote:
 I don't immediately see what the clash in that context would be - I
 *think* what you propose should be doable. I'd be interested to know
 what you come up with, or I might have a look at it myself when I find
 a few minutes to spare.

 I've found that I can add a production

 atype :: { Type }
  ...
  | '{' trueexp '}'

 if I remove the productions for record declarations

 constr1 :: { ConDecl }
      | con '{' '}'                   { RecDecl $1 [] }
      | con '{' fielddecls '}'        { RecDecl $1 (reverse $3) }

 which suggests that it is indeed the syntax

  data Moo = Foo {goo :: Boo Hoo}

 which is in apparent conflict with my proposed extension.
 The current parser uses the type parser btype to parse the
 initial segment of constructor declarations, so my change
 causes trouble.

 Further trouble is in store from infix constructors

  data Noo = Foo {True} :*: Foo {False}

 should make sense, but you have to look quite far to
 distinguish that from a record.

 So I don't see that my proposed extension introduces a
 genuine ambiguity, but it does make the parser a bit
 knottier.

Remember that even though your parser in unambiguous that doesn't mean
that happy will be able to handle it. Happy deals with LALR grammars
and you have to confine yourself to that restriction in order to make
happy happy. Also, your example above suggests that your grammar might
require an infinite lookahead, something which happy doesn't deal
with.

Having said all this, there is a magic flag which you can give to
happy which will make all these headaches go away. The incantation is
--glr which makes happy produce generalized lr parsers which can deal
even with ambiguous grammars. I've never used this myself so I can't
give you any further advice than to point you in the general
direction. The happy manual is your friend.

Happy happy hacking.

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


Re: [Haskell-cafe] glut installation using cabal failed

2009-04-17 Thread Henk-Jan van Tuyl
On Thu, 16 Apr 2009 09:44:44 +0200, Duncan Coutts  
duncan.cou...@worc.ox.ac.uk wrote:



On Wed, 2009-04-15 at 01:53 +0200, Henk-Jan van Tuyl wrote:
On Tue, 14 Apr 2009 08:25:52 +0200, Raja Koduru kscr...@gmail.com  
wrote:


 hi,

 I am a beginner to haskell.

 I am trying to install glut using cabal install glut
 Pasting here a tail of the output



 checking for GLUT/glut.h... no
 configure: error: no GLUT header found, so this package cannot be  
built

 See `config.log' for more details.




 But I do have glut.h in my D:\ghc\ghc-6.10.2\include\mingw\GL.


Define the environment variable:
   C_INCLUDE_PATH=D:\ghc\ghc-6.10.2\include\mingw
(you can add more directories, separate them by ';')
To let the linker find the libraries, define LIBRARY_PATH.


Hmm, that is annoying.

I've filed a tracker bug here:
http://trac.haskell.org/haskell-platform/ticket/11

and also noted the issue here:
http://hackage.haskell.org/trac/hackage/ticket/458#comment:2

Duncan



I am not absolutely sure, that you need to set these environment vars in  
this case, but I needed it for most packages with headers and external  
libs; this is what Raja wrote to me:



Thank you.
 Actually I have already set C_INCLUDE_PATH environment variable with
the right set of directories.
Even after that error trace was occurring.
 I was suggested that I launch cabal from msys instead of launching via
window's cmd.exe.
That worked. I have no explanation for that behavior.
 regards,
raja



--
Regards,
Henk-Jan van Tuyl


--
http://functor.bamikanarie.com
http://Van.Tuyl.eu/
--


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


RE: [Haskell-cafe] types and braces

2009-04-17 Thread Simon Peyton-Jones
Conor

See this, which I've just written for you:
http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/Parser

(Others: please do add to this new Commentary page.)

In any case, my guess is that adding

atype ::= '{' qcon '}'

ought not to introduce ambiguities.  You don't want all of 'exp' (yet) do you?

Simon

| -Original Message-
| From: haskell-cafe-boun...@haskell.org 
[mailto:haskell-cafe-boun...@haskell.org] On
| Behalf Of Conor McBride
| Sent: 15 April 2009 16:13
| To: Lennart Augustsson
| Cc: Haskell Cafe
| Subject: Re: [Haskell-cafe] types and braces
|
|
| On 15 Apr 2009, at 16:01, Lennart Augustsson wrote:
|
|  I'd suggest using some different kind of brackets to relieve the
|  misery, like {| |}.
|
| That would speed up my tinkering, certainly.
|
| I did have a d'oh moment: you can write
|
|data Foo = Moo {goo :: Int}  -- braces where a type goes
|
| and indeed, commenting out field declarations makes happy
| happy. However, these { exp } guys never stand as types of
| things, only as parameters of types, so it might be possible
| to resolve the problem without fat brackets. Whether it's
| worth it is another matter...
|
| Cheers
|
| Conor
|
| ___
| 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] Parsec question

2009-04-17 Thread Michael Mossey



Jason Dusek wrote:

2009/04/17 minh thu not...@gmail.com:

2009/04/17 Michael Mossey m...@alumni.caltech.edu:

I wonder how I can get the manyTill to be happy with eof
before finding the //? I tried

parseText = manyTill anyChar (try (string //) | eof)

but got a type error.

You can use 'notFollowedBy' [...]


  You get a type error because `string //` parses to a
  `String` while `eof` parses to a `()`. Instead you might use:

parseText = manyTill anyChar (try (string //  return ()) | eof)

--
Jason Dusek


Ah.. I think I get it... in the function manyTill, the second argument type doesn't 
matter.. doesn't have to match the first argument type.


Here's what I have so far. It works, but it's a bit weird to consume the // as part 
of the text rather than the keyword. That happens because the try( string // ), 
which is part of the end arg to manyTill, consumes the // when it succeeds. But maybe 
it is the most natural way to express the problem.


parseKeyword :: Parser String
parseKeyword = many1 (alphaNum | char '_')

parseText :: Parser String
parseText = manyTill anyChar ((try (string //)  return ())
  | eof)

parsePair :: Parser (String,String)
parsePair = do k - parseKeyword
   t - parseText
   return (k,t)

parseFile :: Parser [(String,String)]
parseFile = do _ - parseText   -- to skip any text at beginning and 'sync up'
   p - many parsePair
   return p
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re[2]: [Haskell-cafe] RE: [Announce] primes

2009-04-17 Thread Bulat Ziganshin
Hello michael,

Friday, April 17, 2009, 6:26:33 PM, you wrote:

http://haskell.org/cabal/

 You're right. Since I'm not familiar with Cabal, I didn't use it. Is there a 
 good tutorial? Docs?

 Also, I'm running a 32-bit Linux OS. Does one get a significant speed 
 increase by
 switching to a 64-bit OS?

 Thanks for the feedback.

 Michael

 --- On Fri, 4/17/09, Sebastian Fischer
 s...@informatik.uni-kiel.de wrote:

 From: Sebastian Fischer s...@informatik.uni-kiel.de
 Subject: Re: [Haskell-cafe] RE: [Announce] primes
 To: Haskell Cafe mailing list haskell-cafe@haskell.org
 Date: Friday, April 17, 2009, 4:03 AM

 Oh, I just remembered, I'm using ghci. I'll bet that's why I'm so slow.

 I also did, but after installing the package using cabal. IIRC,
 cabal compiles with -O2 by default. But if you downloaded the
 tarball and then loaded the module in ghci without installing it,
 this is probably the reason for the slow response.

 Cheers,
 Sebastian

 -Inline  Attachment Follows-

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


   


-- 
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] Re: Parsec question

2009-04-17 Thread Christian Maeder
Michael Mossey wrote:
 Here's what I have so far. It works, but it's a bit weird to consume the
 // as part of the text rather than the keyword. That happens because the
 try( string // ), which is part of the end arg to manyTill, consumes
 the // when it succeeds. But maybe it is the most natural way to express
 the problem.

use lookAhead!

 parseKeyword :: Parser String
 parseKeyword = many1 (alphaNum | char '_')

  parseKeyword = string //  many1 (alphaNum | char '_')

 parseText :: Parser String
 parseText = manyTill anyChar ((try (string //)  return ())
   | eof)

  parseText = manyTill anyChar
$ (lookAhead (try $ string //)  return ())
  | eof

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


Re: [Haskell-cafe] Haskell Weekly News: Issue 114 - April 17, 2009

2009-04-17 Thread Martijn van Steenbergen

Brent Yorgey wrote:

   The [2]5th Haskell Hackathon is underway in Utrecht! Happy Haskell
   hacking! An early HWN this week since I will be traveling this weekend
   (but not, unfortunately, to the Hackathon).


Yes! It's been a good day so far; there are lots of projects being
worked on. You can follow the [1]latest news on Twitter; there are also
[2]some pictures online already.

[1] http://search.twitter.com/search?q=%23hac5
[2] http://martijn.van.steenbergen.nl/journal/hac5-pt-1/

Groetjes from Utrecht,

Martijn.

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


[Haskell-cafe] Computing a sorted list of products lazily

2009-04-17 Thread Jason Dagit
Hello,

A colleague of mine recently asked if I knew of a lazy way to solve
the following problem:
Given two sets of sorted floating point numbers, can we lazily
generate a sorted list of the products from their Cartesian product?

The algorithm should return the same result as:
sortProduct a b = sort [ x * y | x - a, y - b ]

But, my friend is not satisfied with the strictness of sort.  In
particular, he doesn't want to have to hold the whole list in memory
to sort it.  He would like to compute the results one product at a
time and in the correct order.

Is there an existing algorithm for this problem?  We searched but we
don't seem to know the right search terms.  Additionally, my friend is
not writing this in Haskell, but a Haskell solution is fine because we
should be able to transform it into a Java solution by hand.

We think we know an algorithm that will produce the right result but
it's a bit messy and we doubt we're the first to tackle this problem.
Any help would be greatly appreciated.  Thanks in advance!

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


Re: [Haskell-cafe] Computing a sorted list of products lazily

2009-04-17 Thread porges

I did something similar a while ago to solve a problem posted on StackOverflow:

http://porg.es/blog/sorted-sums-of-a-sorted-list

Henry Laxen generalized my code a little bit so you can pass in any monotonic 
function (see the comments).

I'm not sure of the laziness properties of this, but it might be lazy enough... 
you may need to swap for a boxed array.

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


Re: [Haskell-cafe] Computing a sorted list of products lazily

2009-04-17 Thread Bulat Ziganshin
Hello Jason,

Saturday, April 18, 2009, 1:41:18 AM, you wrote:

 The algorithm should return the same result as:
 sortProduct a b = sort [ x * y | x - a, y - b ]

i think it's well-known problem. you should write a function merging
infinite list of sorted lists. in assumption that lists are ordered by
their first element this should be doable

-- Function that merge finite lists (kidnapped from Data.List):
merge_lists :: (a - a - Ordering) - [[a]] - [a]
merge_lists cmp [] = []
merge_lists cmp [xs] = xs
merge_lists cmp xss = merge_lists cmp (merge_pairs cmp xss)

merge_pairs :: (a - a - Ordering) - [[a]] - [[a]]
merge_pairs cmp [] = []
merge_pairs cmp [xs] = [xs]
merge_pairs cmp (xs:ys:xss) = merge cmp xs ys : merge_pairs cmp xss

merge :: (a - a - Ordering) - [a] - [a] - [a]
merge cmp xs [] = xs
merge cmp [] ys = ys
merge cmp (x:xs) (y:ys)
 = case x `cmp` y of
GT - y : merge cmp (x:xs)   ys
_  - x : merge cmpxs (y:ys)


this function merges lists in pairs. rewriting it to make incremental
merging, using sorted by first element property and omitting finite
lists support, we get just: 

-- Merging infinite sorted lists
merge_lists :: (Ord a) = [[a]] - [a]
merge_lists ((x:xs):xss) = x : merge xs (merge_lists xss)

merge :: (Ord a) = [a] - [a] - [a]
merge (x:xs) (y:ys)
 = case x  y of
True - y : merge (x:xs)   ys
_- x : mergexs (y:ys)


works for me with test script:

main = putStr (unlines$ map show$ merge_lists [[x*y | x-[1..]]  |  y-[1..]])






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

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


Re: [Haskell-cafe] Computing a sorted list of products lazily

2009-04-17 Thread Daniel Fischer
Am Freitag 17 April 2009 23:41:18 schrieb Jason Dagit:
 Hello,

 A colleague of mine recently asked if I knew of a lazy way to solve
 the following problem:
 Given two sets of sorted floating point numbers, can we lazily
 generate a sorted list of the products from their Cartesian product?

If the numbers are nonnegative, you could use

sortedProducts xs ys = foldr merge1 [] [map (*x) ys | x - xs]

merge1 (x:xs) ys = x:merge xs ys
merge1 [] ys = ys

merge xs@(x:xt) ys@(y:yt)
| x  y= x:merge xt ys
| otherwise = y:merge xs yt
(or remove duplicates, if you wish)

Since the lists are sorted and the numbers nonnegative, each (map (*x) ys) is 
sorted and 
the heads of these are sorted, too, therefore we can use merge1, which makes 
the fold lazy 
enough to work even on infinite lists (it is not very fast, though, if speed is 
crucial, 
you might be better off to sort in chunks).



 The algorithm should return the same result as:
 sortProduct a b = sort [ x * y | x - a, y - b ]

 But, my friend is not satisfied with the strictness of sort.  In
 particular, he doesn't want to have to hold the whole list in memory
 to sort it.  He would like to compute the results one product at a
 time and in the correct order.

 Is there an existing algorithm for this problem?  We searched but we
 don't seem to know the right search terms.  Additionally, my friend is
 not writing this in Haskell, but a Haskell solution is fine because we
 should be able to transform it into a Java solution by hand.

 We think we know an algorithm that will produce the right result but
 it's a bit messy and we doubt we're the first to tackle this problem.
 Any help would be greatly appreciated.  Thanks in advance!

 Jason

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


Re: [Haskell-cafe] Computing a sorted list of products lazily

2009-04-17 Thread Martijn van Steenbergen

Hi Daniel,

I love your solution. Very elegant.

Daniel Fischer wrote:

sortedProducts xs ys = foldr merge1 [] [map (*x) ys | x - xs]

merge1 (x:xs) ys = x:merge xs ys
merge1 [] ys = ys

merge xs@(x:xt) ys@(y:yt)
| x  y= x:merge xt ys
| otherwise = y:merge xs yt
(or remove duplicates, if you wish)


Small addition: if you want this to run on finite input as well, add 
this case:


 merge xs ys = xs ++ ys

Martijn.

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


Re: [Haskell-cafe] Computing a sorted list of products lazily

2009-04-17 Thread Daniel Fischer
Am Samstag 18 April 2009 00:31:50 schrieb Martijn van Steenbergen:
 Hi Daniel,

 I love your solution. Very elegant.

 Daniel Fischer wrote:
  sortedProducts xs ys = foldr merge1 [] [map (*x) ys | x - xs]
 
  merge1 (x:xs) ys = x:merge xs ys
  merge1 [] ys = ys
 
  merge xs@(x:xt) ys@(y:yt)
 
  | x  y= x:merge xt ys
  | otherwise = y:merge xs yt
 
  (or remove duplicates, if you wish)

 Small addition: if you want this to run on finite input as well, add

 this case:
   merge xs ys = xs ++ ys

Argh! When typing the foldr, I thought I mustn't forget the case for an empty 
list in 
merge1 and merge. Well, at least I remembered half of it :(


 Martijn.

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


Re: [Haskell-cafe] Computing a sorted list of products lazily

2009-04-17 Thread Tillmann Rendel

Jason Dagit wrote:

A colleague of mine recently asked if I knew of a lazy way to solve
the following problem:
Given two sets of sorted floating point numbers, can we lazily
generate a sorted list of the products from their Cartesian product?

The algorithm should return the same result as:
sortProduct a b = sort [ x * y | x - a, y - b ]


First create a matrix of all the products, represented as a list of 
non-empty lists such that the inner lists are sorted, and the outer list 
is sorted by the first elements of the inner lists. Then repeatedly 
remove the first element of the first list, and reorder the list-of-lists.


 module SortProduct where

 import Data.List (insertBy)
 import Data.Function (on)

 products a b = [[x * y | x - a] | y - b]

 toList [] = []
 toList ([x] : rest) = x : toList rest
 toList ((x : xs) : rest)
   = x : toList (insertBy (compare `on` head) xs rest)

 sortProduct a b = toList (products a b)

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


[Haskell-cafe] Announce: funsat-0.6

2009-04-17 Thread Denis Bueno
Hello haskell-cafe,

funsat is a modern, DPLL-style SAT solver written in Haskell.  Funsat
solves formulas in conjunctive normal form and produces a total
variable assignment for satisfiable problems.  Funsat is intended to
be reasonably efficient for practical problems and convenient to use
as a constraint-solving backend in other software.

Version 0.6 is available from Hackage:

* http://hackage.haskell.org/cgi-bin/hackage-scripts/package/funsat

New in 0.6:

* A representation for logical circuits (and, or, not, onlyif,
iff, if-then-else) supporting efficient conversion to CNF (for
solving) has been added.
* Now uses the BSD3 license.

Please report any bugs to the github page linked from hackage.
  Denis
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsec question

2009-04-17 Thread Michael P Mossey
I've just about got this parser working, but wondering about something. Turns 
out I need try inside the lookahead here.


parseText :: Parser String
parseText = manyTill anyChar $ lookAhead (try (string //))

Without try, if I give it an input with a single slash, like

some/text

It stops with the error unexpected t; expecting //


I'm curious why that happens when lookAhead is used with manyTill like this. I 
was under the impression that if the end parser given to manyTill failed, then 
manyTill would just continue with the main parser. Apparently there are two ways 
to fail: in some contexts, failing means that manyTill will just continue. In 
other contexts, such as the one above, there is some sense in which 'string' 
demands the entire string to be present. Can anyone explain?


Thanks,
Mike

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


Re: [Haskell-cafe] Code Golf

2009-04-17 Thread Sjoerd Visscher

Hi,

This one works for all 3 examples you gave:

diag = concat . takeWhile (not.null)
 . foldr1 (flip $ zipWith (flip (++)) . ([]:))
 . map ((++ repeat []) . map (:[]))

or, using Matt Hellige's pointless fun
http://matt.immute.net/content/pointless-fun

diag = foldr1 (zipWith (++) $. id ~ ([]:) ~ id)
 $. map (++ repeat []) ~ takeWhile (not.null)
 $. (map.map) (:[]) ~ concat

I think the second one is quite readable, thanks to Matt's notation.  
The essential part is up front, and the pre- and post-transformations  
that belong to each other can be grouped.


greetings,
--
Sjoerd Visscher
sjo...@w3future.com



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


Re: [Haskell-cafe] Parsec question

2009-04-17 Thread Daniel Fischer
Am Samstag 18 April 2009 01:33:44 schrieb Michael P Mossey:
 I've just about got this parser working, but wondering about something.
 Turns out I need try inside the lookahead here.

 parseText :: Parser String
 parseText = manyTill anyChar $ lookAhead (try (string //))

 Without try, if I give it an input with a single slash, like

 some/text

 It stops with the error unexpected t; expecting //


 I'm curious why that happens when lookAhead is used with manyTill like
 this. I was under the impression that if the end parser given to manyTill
 failed, then manyTill would just continue with the main parser. Apparently
 there are two ways to fail: in some contexts, failing means that manyTill
 will just continue. In other contexts, such as the one above, there is some
 sense in which 'string' demands the entire string to be present. Can anyone
 explain?


Looking at the source:


manyTill :: GenParser tok st a - GenParser tok st end - GenParser tok st [a]
manyTill p end  = scan
where
  scan  = do{ end; return [] }
|
  do{ x - p; xs - scan; return (x:xs) }

if end fails after consuming some input, manyTill p end fails.


lookAhead :: GenParser tok st a - GenParser tok st a
lookAhead p = do{ state - getParserState
; x - p
; setParserState state
; return x
}

lookAhead fails if p fails, but if p fails, the state is not reset, so if p 
fails after 
consuming some input, like in your example some/text, where lookAhead (string 
//) 
consumes the slash and fails because the second expected slash is missing, that 
is not put 
back and since something is consumed, the second branch of scan in manyTill 
isn't tried.

You could also have

keyword = try $ do
string //
kw - many1 keywordChar
return (Keyword kw)

parseText = manyTill anyChar (lookAhead keyword)

Seems cleaner to have the slashes in keyword.


 Thanks,
 Mike


Cheers,
Daniel

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


[Haskell-cafe] Synchronising cabal package version with self-reported version

2009-04-17 Thread Denis Bueno
Hi all,

In a command-line app of mine I want to have a --version flag, like
many GNU apps do to report their version.  The only way I know to
provide the version number is to hardcode it in the source code
somewhere.  That means I have the version number in two places: the
.cabal file and the source code.  I just know that one day they'll get
unsynchronised, and --version will be wrong.

Is there any way to put the version number in _one_ place, and have
both the .cabal and source refer to it?  Or even any easier way to
synchronise both version numbers?

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


Re: [Haskell-cafe] Synchronising cabal package version with self-reported version

2009-04-17 Thread Don Stewart
dbueno:
 Hi all,
 
 In a command-line app of mine I want to have a --version flag, like
 many GNU apps do to report their version.  The only way I know to
 provide the version number is to hardcode it in the source code
 somewhere.  That means I have the version number in two places: the
 .cabal file and the source code.  I just know that one day they'll get
 unsynchronised, and --version will be wrong.
 
 Is there any way to put the version number in _one_ place, and have
 both the .cabal and source refer to it?  Or even any easier way to
 synchronise both version numbers?

Yes, cabal provides support for this. Here's how we do that in xmonad.

In your program, import the magic module Paths_$progname:

import Paths_xmonad (version)

[--version] - putStrLn (xmonad  ++ showVersion version) 

which provides many fields from the .cabal file used to compile the
program.

In your .cabal file , have something like:

name:   xmonad
version:0.8.1

Problem solved :)
Look in

$ vim dist/build/autogen/Paths_xmonad.hs

to see what you get to play with:

module Paths_xmonad (
version,
getBinDir, getLibDir, getDataDir, getLibexecDir,
getDataFileName
  ) where

import Data.Version (Version(..))
import System.Environment (getEnv)

version :: Version
version = Version {versionBranch = [0,8,1], versionTags = []}

bindir, libdir, datadir, libexecdir :: FilePath

bindir = /home/dons/.cabal/bin
libdir = /home/dons/.cabal/lib/xmonad-0.8.1/ghc-6.10.1
datadir= /home/dons/.cabal/share/xmonad-0.8.1
libexecdir = /home/dons/.cabal/libexec

getBinDir, getLibDir, getDataDir, getLibexecDir :: IO FilePath
getBinDir = catch (getEnv xmonad_bindir) (\_ - return bindir)
getLibDir = catch (getEnv xmonad_libdir) (\_ - return libdir)
getDataDir = catch (getEnv xmonad_datadir) (\_ - return datadir)
getLibexecDir = catch (getEnv xmonad_libexecdir) (\_ - return libexecdir)

getDataFileName :: FilePath - IO FilePath
getDataFileName name = do
  dir - getDataDir
  return (dir ++ / ++ name)

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