[Haskell-cafe] where do I point the type annotations

2007-05-18 Thread Alex Jacobson
I am playing with using SYB to make generic indexed collections. The current code is this: data Syb = Syb [Dynamic] -- list of [Map val (Set a)] empty item = Syb $ gmapQ (toDyn . emp item) item where emp::x-y-Map.Map y (Set.Set x) emp x y = Map.empty insert x

[Haskell-cafe] Debunking tail recursion

2007-05-18 Thread Jules Bean
A conversation on #haskell just showed that it's quite hard to explain (at least it is for me) to people attached to tail recursion why that is a red herring in Haskell. I had a poke around the wiki and couldn't see a page which explains it clearly. In fact

[Haskell-cafe] Module dependency graph generator

2007-05-18 Thread Alfonso Acosta
Hi all, I'm searching for a tool which generates a module dependency graph (a graphviz backend would be more than enough). Does anybody know a tool with such functionality? Cheers, Fons ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

[Haskell-cafe] Re: Tail Recursion within the IO Monad

2007-05-18 Thread Simon Marlow
Stefan O'Rear wrote: On Thu, May 17, 2007 at 11:22:34AM +0100, Simon Marlow wrote: sequence still isn't tail-recursive, although sequence_ is. If you want a tail-recursive sequence, the only way to do it is like this: sequence' :: [IO a] - IO [a] sequence' ms = do let as = map

RE: [Haskell-cafe] global variables

2007-05-18 Thread Simon Peyton-Jones
| and (at worst) are evil. These people are quite simply wrong and | should be ignored :-) | | Adrian Hey is not only wrong, but actually evil. He should be ignored. :-) | | I am right, I might well be evil, and if past experience is anything to | go by I already know that I will be ignored.

Re: [Haskell-cafe] writer monad help

2007-05-18 Thread Jules Bean
iskaldur wrote: I'm trying to learn to use the Writer Monad, but I'm having trouble with the following very simple program: import Control.Monad.Writer foo :: Writer String Int foo = tell hello Basically, I was trying to figure out the 'tell' function, so I want foo to return ((), hello).

[Haskell-cafe] writer monad help

2007-05-18 Thread iskaldur
I'm trying to learn to use the Writer Monad, but I'm having trouble with the following very simple program: import Control.Monad.Writer foo :: Writer String Int foo = tell hello Basically, I was trying to figure out the 'tell' function, so I want foo to return ((), hello). But I get this

Re: [Haskell-cafe] reversing big list with constant heap space used

2007-05-18 Thread Henning Thielemann
On Wed, 16 May 2007, Evan Laforge wrote: I think that in every particular case you have to find out how to avoid 'reverse'. Especially if you have two 'reverse's like in reverse . dropWhile p . reverse there are more efficient solutions. Just from curiosity, what *is* an efficient

Re: [Haskell-cafe] global variables

2007-05-18 Thread Henning Thielemann
On Thu, 17 May 2007, Jules Bean wrote: Eric wrote: H|i, Does anyone know of a simple and straightforward way to use global variables in Haskell? (Perhaps annoyingly) the answer to this question, like so many other questions on this list, is a question. What are you trying to do?.

Re: [Haskell-cafe] writer monad help

2007-05-18 Thread Brandon S. Allbery KF8NH
On May 18, 2007, at 7:32 , iskaldur wrote: import Control.Monad.Writer foo :: Writer String Int foo = tell hello foo = tell hello return 1 -- or whatever You declared it to return Int, you should probably produce an Int somewhere -- brandon s. allbery

Re: [Haskell-cafe] Quick Sort Algorithm

2007-05-18 Thread Malcolm Wallace
PR Stanley [EMAIL PROTECTED] wrote: No, Mr. smarty pants, I can't. I'll leave you to work out why I rely on a scanner and an OCR engine for reading printed materials. *smile* Ah. Well, given your original question (why does this code not work?) it was probably a reasonable assumption that

Re: [Haskell-cafe] global variables

2007-05-18 Thread Jules Bean
[I agree with your points, but...] Adrian Hey wrote: I've pretty much convinced it's wrong. There should be one and only one main from which all subsequent IO activity derives. But creating internal state in the form of mutable data structures is not an IO activity. It just so happens that at

Re: [Haskell-cafe] global variables

2007-05-18 Thread Adrian Hey
Jules Bean wrote: main = do sockstate - initSocks graphstate - initGraphics ... disposeGraphics graphstate disposeSocks sockstate exit Voila. Mutable state which persists for our entire program. Arguably it's a pain passing around the state explicitly. Alternatively, you can

Re: [Haskell-cafe] Debunking tail recursion

2007-05-18 Thread Juan Carlos Arevalo Baeza
On Fri, 18 May 2007 01:52:11 -0700, Jules Bean [EMAIL PROTECTED] wrote: A conversation on #haskell just showed that it's quite hard to explain (at least it is for me) to people attached to tail recursion why that is a red herring in Haskell. If someone has the energy and the clarity to

Re: [Haskell-cafe] Quick Sort Algorithm

2007-05-18 Thread PR Stanley
Dear Sir, At the risk of seeming a little pedantic let me remind you that Andrew's remark was in reply to the following message: start message Well, actually, this was scanned from a book but the OCR process wasn't 100% effective. So, I was hoping the list would easily identify and replace

Re: [Haskell-cafe] global variables

2007-05-18 Thread Adrian Hey
Simon Peyton-Jones wrote: For example, I was looking back at your ACIO mail a couple of months ago, when I was thinking about concurrency. Actually, this is Ian Starks proposal.. http://www.haskell.org/pipermail/haskell-cafe/2004-November/007664.html ..but is one with which I agree. I just

Re: [Haskell-cafe] Short and sweet

2007-05-18 Thread Neil Mitchell
Hi Can anybody tell me what complexity class nub belongs to? nub requires Eq and not Ord, therefore you can prove that _any_ nub, no matter how good it is, must be O(n^2). Thanks Neil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

[Haskell-cafe] Short and sweet

2007-05-18 Thread Andrew Coppin
Greetings. Can anybody tell me what complexity class nub belongs to? (The implementation in the Language Report appears to have n^2 complexity. Do the actual implementations out there follow?) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

RE: [Haskell-cafe] Module dependency graph generator

2007-05-18 Thread José Miguel Vilaça
Take a look to HaSlicer (http://labdotnet.di.uminho.pt/HaSlicer/HaSlicer.aspx). It can do that. Best Miguel Vilaça -Mensagem original- De: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Em nome de Alfonso Acosta Enviada: sexta-feira, 18 de Maio de 2007 12:11 Para: Haskell-cafe Assunto:

[Haskell-cafe] Made me smile

2007-05-18 Thread Andrew Coppin
OK, so I was hanging out on this newsgroup I often lurk. And we're having a discussion. And I'm all like Haskell is the greatest! And they're all like nah, Haskell sux. And this one dude goes hey, look at this C++ code. How do you do that in Haskell? And three other people look at this C++ and

Re: [Haskell-cafe] Short and sweet

2007-05-18 Thread Paul Johnson
Andrew Coppin wrote: It occurs to me that if you want a sorted list of only unique elements, it would seem (to me) to be efficient to do the sorting and the uniquing at the same time. Does any library function do this? (I imagine it wouldn't be hard to write it yourself...) Yes, although it

Re: [Haskell-cafe] Debunking tail recursion

2007-05-18 Thread David House
On 18/05/07, Albert Y. C. Lai [EMAIL PROTECTED] wrote: Lazy evaluation says, to evaluate x, call f first, then x is the last call. x may be the last to be evaluated, but you still have to pass through f's call context 'on the way out'. For example, suppose in the expression 'f x y' you have f

Re: [Haskell-cafe] Help with Programming in Haskell example

2007-05-18 Thread Tillmann Rendel
Hello, Andre Nathan schrieb: so I'm wondering what else I need to do for the do notation to work. import Prelude hiding ((=), return) You explicitly ask for the well-known and standard functions = and return to be hidden away, because you want to define your own versions. p :: Parser

Re: [Haskell-cafe] global variables

2007-05-18 Thread Isaac Dupree
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Adrian Hey wrote: Furthermore, if it is going to take this state handle as an explicit argument then you need to provide some way for users to get this state handle. This could be by.. 1 - Making it an argument of main. 2 - Exposing a

Re: [Haskell-cafe] Help with Programming in Haskell example

2007-05-18 Thread Andre Nathan
On Fri, 2007-05-18 at 22:32 +0200, Tillmann Rendel wrote: [snip] Now you should be able to use do notation with your own Parser type. Thanks! Monads and instances weren't mentioned until that point, so I was assuming that all that was needed for the do notation to work was having (=) and return

Re: [Haskell-cafe] global variables

2007-05-18 Thread John Meacham
On Thu, May 17, 2007 at 07:25:03PM +0100, Adrian Hey wrote: The above hack is not actually Haskell. It's a hack, and it depends on the particular implementation characteristics of GHC. It is not unreasonable to imagine that a future GHC might contain different compilation techniques (I

Re: [Haskell-cafe] global variables

2007-05-18 Thread John Meacham
On Thu, May 17, 2007 at 11:00:18PM +0100, Jules Bean wrote: I'm not sure that's quite to the point. Clearly we can set up state at the top of our main action: main = do sockstate - initSocks graphstate - initGraphics ... disposeGraphics graphstate disposeSocks sockstate

Re: [Haskell-cafe] Made me smile

2007-05-18 Thread Dan Piponi
If you allow me to play Devil's advocate for a moment...just don't let this guy ask you how long the Haskell version takes. In fact, you can borrow a trick from the C++ version. Try this instead: import Data.Set main = interact $ unlines . toList . fromList . words Assuming Data.Set is

Re: [Haskell-cafe] Short and sweet

2007-05-18 Thread Dan Weston
OK, I looked up group and didn't see any Ord constraint analog. I give up. What is the common idiom? I was stupidly using nub even though I already have an Ord constraint. I have rewritten it to: unique :: Ord a = [a] - [a] unique (x:y:z) = (if x y then (x:) else id) (unique (y:z)) unique xyz

Re: [Haskell-cafe] Made me smile

2007-05-18 Thread Dan Weston
How does the type of fromList get determined? And is Data.Set.toList the same as Data.Set.toAscList? Dan Piponi wrote: If you allow me to play Devil's advocate for a moment...just don't let this guy ask you how long the Haskell version takes. In fact, you can borrow a trick from the C++

Re: [Haskell-cafe] Short and sweet

2007-05-18 Thread Rodrigo Queiro
group collects equal elements in sublists. Thus, unique can be implemented as: unique = map head . group i.e. taking the first of each group of equal elements. (Yet) another way of doing this, is a modified quicksort: qsort [] = [] qsort (x:xs) = qsort (filter (x) xs) ++ [x] ++ qsort (filter

Re: [Haskell-cafe] where do I point the type annotations

2007-05-18 Thread Brandon Michael Moore
On Fri, May 18, 2007 at 02:39:48AM -0400, Alex Jacobson wrote: I am playing with using SYB to make generic indexed collections. The current code is this: data Syb = Syb [Dynamic] -- list of [Map val (Set a)] empty item = Syb $ gmapQ (toDyn . emp item) item where

Re: [Haskell-cafe] Made me smile

2007-05-18 Thread Dan Piponi
On 5/18/07, Dan Weston [EMAIL PROTECTED] wrote: How does the type of fromList get determined? And is Data.Set.toList the same as Data.Set.toAscList? As I import just Data.Set there is only one fromList in scope. It has type (Ord a) = [a] - Set a so there is no ambiguity. I should have used

Re: [Haskell-cafe] Picking an architecture for a Haskell web app

2007-05-18 Thread John Meacham
On Fri, May 11, 2007 at 12:00:10AM +0200, Lennart Augustsson wrote: Parsing a very close approximation to what Haskell specifies isn't that hard. You just need some mild interaction between the parser and lexer. This algorithm can correctly de-whitespace haskell without any parser