Re: [Haskell-cafe] case of (was: [Haskell] Mixing monadic and non-monadic functions)

2005-09-20 Thread Henning Thielemann
On Mon, 19 Sep 2005, Andrew Pimlott wrote: On Sat, Sep 17, 2005 at 06:56:36PM +0100, Ben Rudiak-Gould wrote: * The new syntax is really nice as a replacement for the annoyingly common x - foo ; case x of... idiom that I've always disliked. I might wish for case of to mean \x - case

Re: [Haskell-cafe] case of (was: [Haskell] Mixing monadic and non-monadic functions)

2005-09-20 Thread Sven Moritz Hallberg
Donn Cave schrieb: The ordinary lambda comes close - in ghc anyway, it supports pattern matching. But I can't work out the syntax for multiple cases, which would obviously be needed to make it practically useful. e.g., this seems to be OK: getArgs = \ (a:_) - putStrLn (show a) but

[Haskell-cafe] TH Q Monad and fail

2005-09-20 Thread Gracjan Polak
Hi all, The Q Monad in template haskell has fail method. As I understand it, it throws some kind of exception. How do I catch this exception? Some code I'm trying to create: infoToCode :: Info - Q Exp infoToCode (ClassI dec) = -- ClassI Dec fail ClassI not supported -- this will be

Re: [Haskell-cafe] case of (was: [Haskell] Mixing monadic and non-monadic functions)

2005-09-20 Thread Bernard Pope
On Tue, 2005-09-20 at 10:14 +0200, Sven Moritz Hallberg wrote: Donn Cave schrieb: The ordinary lambda comes close - in ghc anyway, it supports pattern matching. But I can't work out the syntax for multiple cases, which would obviously be needed to make it practically useful. e.g.,

Re: [Haskell-cafe] Template Haskell and Types

2005-09-20 Thread Gracjan Polak
Simon Peyton-Jones wrote: design note http://research.microsoft.com/~simonpj/tmp/notes2.ps In the above paper there is something about 'giveUp'. Seems to quite useful, but there is no such thing in ghc 6.4. Where did my giveUp go? And why? -- Gracjan

[Haskell-cafe] Re: Network parsing and parsec

2005-09-20 Thread John Goerzen
On 2005-09-16, Andrew Pimlott [EMAIL PROTECTED] wrote: On Thu, Sep 15, 2005 at 06:11:58PM -0700, Andrew Pimlott wrote: I don't see why this would be more error-prone than any other approach. Hmm... I take that back. I don't know anything about the IMAP protocol, but after imagining for a few

[Haskell-cafe] Re: Network parsing and parsec

2005-09-20 Thread John Goerzen
On 2005-09-15, Adam Turoff [EMAIL PROTECTED] wrote: On 9/15/05, John Goerzen [EMAIL PROTECTED] wrote: So, to make that approach work, I would really need to do a lot of work outside of Parsec -- the stuff that I really want to use Parsec for, I think. Well, you do have a state monad to work

Re: [Haskell-cafe] Re: Network parsing and parsec

2005-09-20 Thread Keean Schupke
John Goerzen wrote: On 2005-09-15, Adam Turoff [EMAIL PROTECTED] wrote: On 9/15/05, John Goerzen [EMAIL PROTECTED] wrote: So, to make that approach work, I would really need to do a lot of work outside of Parsec -- the stuff that I really want to use Parsec for, I think. Well,

Re: [Haskell-cafe] Re: Network parsing and parsec

2005-09-20 Thread Keean Schupke
You may like my parser transformer then (based on the efficent backtracking parser paper, I believe by Ralf Heinze - uses endofunctor and continuation passing - Its a long time since I tested it but I think it holds its own against Parsec, without requiring the extra return types). --

Re: [Haskell-cafe] Use Haskell to extract GXL representation

2005-09-20 Thread Santoemma Enrico
Sara, I've used extensively HaXml and the tool DtdToHaskell to do xml processing. HaXml marshalls/demarshalls xml data and DtdToHaskell creates the data statements to handle xml in haskell fashion. I learnt how to write a palatable DTD for the delicate DtdToHaskell, but in your case I guess

Re: [Haskell-cafe] Re: Network parsing and parsec

2005-09-20 Thread John Goerzen
On Tue, Sep 20, 2005 at 02:29:12PM +0100, Keean Schupke wrote: It's unclear to me exactly how to mix the IO monad with Parsec. It doesn't really seem to be doable. Not to mention that if hGetContents is used, the Handle has to be put into non-buffering mode, which means one syscall per

Re: [Haskell-cafe] Re: Network parsing and parsec

2005-09-20 Thread Keean Schupke
Here's some useful definitions to go with that... module Lib.Parser.Parser(Parser,when,unless,guard,(|),opt,many,many1,sepBy, parse,alpha,digit,lower,upper,other,lexical,satisfy,optional,literal,untilP,untilParser,matchP) where ... (see attachment for files) Regards, Keean.

Re: [Haskell-cafe] Re: Network parsing and parsec

2005-09-20 Thread Keean Schupke
John Goerzen wrote: On Tue, Sep 20, 2005 at 02:29:12PM +0100, Keean Schupke wrote: It's unclear to me exactly how to mix the IO monad with Parsec. It doesn't really seem to be doable. Not to mention that if hGetContents is used, the Handle has to be put into non-buffering mode, which

Re: [Haskell-cafe] Re: Network parsing and parsec

2005-09-20 Thread John Goerzen
On Tue, Sep 20, 2005 at 03:05:25PM +0100, Keean Schupke wrote: strace seems to say yes. Thats odd, the source code seems to suggest that when you read past the end of the buffer it reads the next entire buffer (it has cases for each possible buffer configuration, line, block and none)

Re: [Haskell-cafe] Re: Network parsing and parsec

2005-09-20 Thread Keean Schupke
Here's the code from hGetContents (base/GHC/IO.lhs): -- we never want to block during the read, so we call fillReadBuffer with -- is_line==True, which tells it to just read what there is. lazyReadBuffered h handle_ fd ref buf = do catch (do buf - fillReadBuffer fd

Re: [Haskell-cafe] Re: Network parsing and parsec

2005-09-20 Thread Keean Schupke
John Goerzen wrote: On Tue, Sep 20, 2005 at 03:05:25PM +0100, Keean Schupke wrote: strace seems to say yes. Thats odd, the source code seems to suggest that when you read past the end of the buffer it reads the next entire buffer (it has cases for each possible buffer

Re: [Haskell-cafe] Re: Network parsing and parsec

2005-09-20 Thread John Goerzen
On Tue, Sep 20, 2005 at 03:20:01PM +0100, Keean Schupke wrote: Because the next entire buffer might consume more data than the remote has sent. That results in deadlock. Would it not be usual to have a timeout incase of dropped connection? Yes, but hardly useful if it happens after

Re: [Haskell-cafe] Re: Network parsing and parsec

2005-09-20 Thread John Goerzen
On Tue, Sep 20, 2005 at 03:17:11PM +0100, Keean Schupke wrote: -- For a line buffer, we just get the first chunk of data to arrive, -- and don't wait for the whole buffer to be full (but we *do* wait -- until some data arrives). This isn't really line buffering, but it -- appears

[Haskell-cafe] How to locate a loop?

2005-09-20 Thread Jørgen Hermanrud Fjeld
Hi. I have a generated Haskell program that emits a Fail: loop at runtime. Are there some tools or standard manner for identifying the lines that participate in the loop? The use of -debug and -prof -auto-all only provides a call stack, and the loop is, is I understand it, due to a circular

Re: [Haskell-cafe] How to locate a loop?

2005-09-20 Thread Malcolm Wallace
Jørgen Hermanrud Fjeld [EMAIL PROTECTED] writes: I have a generated Haskell program that emits a Fail: loop at runtime. Are there some tools or standard manner for identifying the lines that participate in the loop? Provided your program does not use too many GHC extensions or fancy

[Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Mark Carter
I'm puzzling out how to get a Bool from am IO Bool. I know I'm not supposed to, but I don't see any way around my predicament. The basic setup is: I have an edit box, and a panel. If you click the LMB on the panel when the edit box is checked, this means you want to move a graphical object

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Neil Mitchell
Take a look at unsafePerformIO, it is of type IO a - a. Its not particularly safe (the name gives a clue), but it does what you want. On 9/20/05, Mark Carter [EMAIL PROTECTED] wrote: I'm puzzling out how to get a Bool from am IO Bool. I know I'm not supposed to, but I don't see any way around

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread robert dockins
Mark Carter wrote: I'm puzzling out how to get a Bool from am IO Bool. I know I'm not supposed to, but I don't see any way around my predicament. The basic setup is: I have an edit box, and a panel. If you click the LMB on the panel when the edit box is checked, this means you want to move

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Piyush P Kurur
On Tue, Sep 20, 2005 at 04:30:25PM +0100, Neil Mitchell wrote: Take a look at unsafePerformIO, it is of type IO a - a. Its not particularly safe (the name gives a clue), but it does what you want. I dont think you would ever need to do unsafePerformIO unless you are writing some lib

[Haskell-cafe] Constructor constraints

2005-09-20 Thread Rich Neswold
Hello,I've looked through the two tutorials and the Report, but couldn't find help on this topic. My question is whether you can place constraints on new data types. For instance, I want to make a new type that is a 4 element tuple where each element is greater than or equal to the previous entry.

Re: [Haskell-cafe] Constructor constraints

2005-09-20 Thread Malcolm Wallace
Rich Neswold [EMAIL PROTECTED] writes: For instance, I want to make a new type that is a 4 element tuple where each element is greater than or equal to the previous entry. data Category = Membership a a a a You can make a 'smart' constructor function, and hide the real data constructor so

Re: [Haskell-cafe] case of (was: [Haskell] Mixing monadic and non-monadic functions)

2005-09-20 Thread Donn Cave
On Tue, 20 Sep 2005, Bernard Pope wrote: On Tue, 2005-09-20 at 10:14 +0200, Sven Moritz Hallberg wrote: Donn Cave schrieb: ... but how do you write getArgs = \ [] - putStrLn (no arguments) (a:_) - putStrLn (show a) What about good old let? main = getArgs

Re: [Haskell-cafe] Constructor constraints

2005-09-20 Thread Rich Neswold
On 9/20/05, Malcolm Wallace [EMAIL PROTECTED] wrote: You can make a 'smart' constructor function, and hide the real dataconstructor so that it cannot be used:Thanks! I'll give your solution a try.-- RichAIM : rnezzy ICQ : 174908475 ___ Haskell-Cafe

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Mark Carter
Greg Buchholz wrote: Have you read... http://haskell.org/hawiki/ThatAnnoyingIoType Thanks. I'll take a look at it. I also need to take a look at the basic Haskell syntax. An interesting-looking web page which discusses monads is: http://www.nomaware.com/monads/html/analogy.html

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Mark Carter
Mark Carter wrote: What struck me was this bit of code: assemblyLine w = (return w) = makeChopsticks = polishChopsticks = wrapChopsticks Interestingly, this looks like Forth (!), where you put a value on the stack, and successive operations fiddle with the stack as a series of

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Bill Wood
. . . What struck me was this bit of code: assemblyLine w = (return w) = makeChopsticks = polishChopsticks = wrapChopsticks Interestingly, this looks like Forth (!), where you put a value on the stack, and successive operations fiddle with the stack as a series of

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Bill Wood
. . . Another thing I noticed in my nano-experience of Haskell is the Maybe monad. This is interesting because it's a bit like a hybrid variables. If you look at a book like Writing Solid Code (or is it Code Complete, I can't remember now) which examine C style, they basically scorn

Re: [Haskell] Re: [Haskell-cafe] Haskell versus Lisp

2005-09-20 Thread David F. Place
On Sep 20, 2005, at 3:43 PM, Glynn Clements wrote: That, in a nutshell, is Lisp's key strength. It uses the same structure for code as for data, which makes it very easy to add new language features. I assume that you refer to `eval' and the fact it operates on conses and symbols. Beyond

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Lennart Augustsson
Mark Carter wrote: The typical example in C is: mem = malloc(1024) Malloc returns 0 to indicate that memory cannot be allocated, or a memory address if it can. The variable mem is a so-called hybrid variable; it crunches together 2 different concepts: a boolean value (could I allocate

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Bill Wood
. . . The typical example in C is: mem = malloc(1024) Malloc returns 0 to indicate that memory cannot be allocated, or a memory address if it can. The variable mem is a so-called hybrid variable; it crunches together 2 different concepts: a boolean value (could I allocate memory?) and

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Mark Carter
Lennart Augustsson wrote: Mark Carter wrote: The typical example in C is: mem = malloc(1024) Malloc returns 0 to indicate that memory cannot be allocated, or a memory address if it can. The variable mem is a so-called hybrid variable; it crunches together 2 different concepts: a boolean

Re: [Haskell] Re: [Haskell-cafe] Haskell versus Lisp

2005-09-20 Thread Glynn Clements
David F. Place wrote: That, in a nutshell, is Lisp's key strength. It uses the same structure for code as for data, which makes it very easy to add new language features. I assume that you refer to `eval' and the fact it operates on conses and symbols. Beyond the extremely

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Michael Walter
Compare: int *p=...; int x=*p; and: let p = ... Just x = p So actually, there is few difference between dereferencing a pointer without checking for 0, and extracting the Maybe value without handling Nothing, apart from that it leads to undefined behavior in C which in fact isn't

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Greg Buchholz
Mark Carter wrote: What struck me was this bit of code: assemblyLine w = (return w) = makeChopsticks = polishChopsticks = wrapChopsticks Interestingly, this looks like Forth (!), where you put a value on the stack, and successive operations fiddle with the stack as a series of

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Glynn Clements
Mark Carter wrote: Could you briefly elaborate on what you mean by hybrid variables? According to Google, hybrid in genetics means The offspring of genetically dissimilar parents or stock, especially the offspring produced by breeding plants or animals of different varieties, species,

Re: [Haskell] Re: [Haskell-cafe] Haskell versus Lisp

2005-09-20 Thread David F. Place
I was hoping that the examples I requested would be examples of particular control constructs or extensions to the language's syntax and semantics. Though I admit that such things are possible in lisp, I suspect that their utility is minimal. On Sep 20, 2005, at 4:55 PM, Glynn Clements

Re: [Haskell] Re: [Haskell-cafe] Haskell versus Lisp

2005-09-20 Thread Bill Wood
. . . I was hoping that the examples I requested would be examples of particular control constructs or extensions to the language's syntax and semantics. Though I admit that such things are possible in lisp, I suspect that their utility is minimal. As to utility, quite the contrary,

Re: [Haskell-cafe] Re: Network parsing and parsec

2005-09-20 Thread Benjamin Franksen
On Tuesday 20 September 2005 16:50, John Goerzen wrote: On the flip side, Parsec is really nice. I wonder how easy it would be to make it parse [Word8] instead of String? Isn't Parsec parameterized over the token type? Or even a FastPackedString? (And how easy it would be to get that

Re: [Haskell] Re: [Haskell-cafe] Haskell versus Lisp

2005-09-20 Thread David F. Place
I don't deny that all of the things you mentioned are wonderful indeed. I just wonder if they really could only be done in lisp or even most conveniently. Many years ago I read a paper by Phil Wadler about logic programing using a functional language. I think it was called something

Re: [Haskell] Re: [Haskell-cafe] Haskell versus Lisp

2005-09-20 Thread Greg Buchholz
Bill Wood wrote: As to utility, quite the contrary, I think. Offhand I can think of the screamer package for Common Lisp, which provides non-deterministic mechanisms for use in backtracking applications. For a while in the 80's there was practically a cottage industry implementing various

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Lennart Augustsson
There's a big difference. You can see you are doing something fishy, and the compiler can too, and it can warn you. -- Lennart Michael Walter wrote: Compare: int *p=...; int x=*p; and: let p = ... Just x = p So actually, there is few difference between dereferencing a

[Haskell-cafe] Basic type classing question.

2005-09-20 Thread Karl Grapone
Hi, I've just started learning Haskell, and I must admit I'm finding it a bit hard to get my head around the typing system... If I wanted to represent Employees and Departments in a Haskell program I could use data declarations like so: data Employee = Emp ... data Department = Dept ... This

Re: [Haskell-cafe] Basic type classing question.

2005-09-20 Thread J. Garrett Morris
On 9/20/05, Karl Grapone [EMAIL PROTECTED] wrote: What I want to be able to do is add and remove fields while the system is running, I suppose via hs-plugins, and I should be prevented from, for example, accidentally taking an employees first name and using it as a departments address. I know