Re: [Haskell-cafe] Lambda and closures in PHP -- could someone please comment?
With respect, do you not think it'd be wiser for the community [snip] *disgusted* This is exactly the sort of message that haskell-cafe does not normally contain. Let's not start now. This is a civilized mailing list. Either comment on the nice gentlemen's PHP closure proposal from a language point of view, or don't say anything. Paul: Uncivilised you say. Well, I would have thought the civilised thing would be to share your concerns discretely with the list moderator. Instead you've chosen to make a public show of it. The Chinese have a saying, and I paraphrase - when you point the finger of accusation at someone/something you have three pointing back at yourself. Paul ___ 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?
PR Stanley wrote: With respect, do you not think it'd be wiser for the community [snip] *disgusted* This is exactly the sort of message that haskell-cafe does not normally contain. Let's not start now. This is a civilized mailing list. Either comment on the nice gentlemen's PHP closure proposal from a language point of view, or don't say anything. Paul: Uncivilised you say. Well, I would have thought the civilised thing would be to share your concerns discretely with the list moderator. Hmm, I wonder who exactly this list moderator is supposed to be. We are usually adult enough around here to not need someone to look after us. I think Jules was well entitled to raise his objections about the tone of your email in public. Paul: As you say, we are adult enougharound here to not need someone to look after us. So I don't need you or any other interfearing busybody to tell me what I can and can't say on Haskell Cafe. I expressed an opinion in a tongue-in-cheek way and at the end of my message expressed in clear terms that those were merely my views. Now, if you, Jules, Alex or some other wannabe Hitler have a problem with my freedom of expression then your best solution is to saddle up and get the hell out yourselves. This is the wrong place for setting up your tinpot dictatorship, Doctor! I am grateful for the help I've been getting from the list and my understanding of FP has vastly improved since my membership of this list but I refuse to tolerate bullies who use the list as a way of lifting themselves out of their own shitty lives. Now I am angry! Instead you've chosen to make a public show of it. The Chinese have a saying, and I paraphrase - when you point the finger of accusation at someone/something you have three pointing back at yourself. Well, at least not this finger... Paul: you're not making sense. ___ 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?
Now, if you, Jules, Alex or some other wannabe Hitler have a problem with my freedom of expression then your best solution is to saddle up and get the hell out yourselves. This is the wrong place for setting up your tinpot dictatorship, Doctor! Just more evidence... http://en.wikipedia.org/wiki/Godwin's_law Paul: I think you're missing a big painfully obvious point here, Mr smarty pants. No, actually, I think I'll leave it at that. I just can't be bothered. However, I'll say this - anyone sticking his bloody big hooter into my business in the future will get a similar reaction! Paul Luke ___ 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?
It seems to me that if a PHP developer sees the Haskell community as a resource for advice on programming language implementation, we should take this as a compliment to the Haskell community. Repaying that compliment with your language sucks rocks strikes me as unwise. I'm familiar with a lot of arguments for why PHP is a poorly-designed language, and have found them sufficiently persuasive that I haven't bothered to learn PHP. But I don't see any point to repeating those arguments on this list. Paul: So, you've never bothered to learn PHP. Well, I happen to know the language very well and therefore feel I am in a good position to express my views about it. Unlike you, I don't base my judgment on rumours and hearsay. It is true that PHP fails to capture the spirit of the classical concept of a function. Type checking in PHP is equally poor. These are not just my opinions. Are we not to say anything critical about a programming language even if it happens to be substantively relevant lestwe should offend someone? God, if you want to stick up for your mates here at least come up with a convincing cover. Paul ___ 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] Lambda and closures in PHP -- could someone please comment?
It seems to me that if a PHP developer sees the Haskell community as a resource for advice on programming language implementation, we should take this as a compliment to the Haskell community. Repaying that compliment with your language sucks rocks strikes me as unwise. Not necessarily. It can be that they'd implement closures in PHP, make a dog's dinner of it (as they always do), and then we would be blamed for giving them bad advice. Anyway, it seems that PR Stanley was forced to use PHP, no wonder he's a little mad at it. Paul: How did you know? :-) You know, the funny thing is that all these so-called civilised people can find time and energy to have a go at me but can't be bothered to help the chap with the original query. ___ 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] Lambda and closures in PHP -- could someone please comment?
It seems to me that if a PHP developer sees the Haskell community as a resource for advice on programming language implementation, we should take this as a compliment to the Haskell community. Repaying that compliment with your language sucks rocks strikes me as unwise. Not necessarily. It can be that they'd implement closures in PHP, make a dog's dinner of it (as they always do), and then we would be blamed for giving them bad advice. Anyway, it seems that PR Stanley was forced to use PHP, no wonder he's a little mad at it. Paul: How did you know? :-) You know, the funny thing is that all these so-called civilised people can find time and energy to have a go at me but can't be bothered to help the chap with the original query. I could, and I think you're full of it, too. So there. Paul: I rest my case! :-) you cowardly hypocrit! ___ 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?
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! ___ 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?
PR Stanley wrote: With respect, do you not think it'd be wiser for the community [snip] *disgusted* This is exactly the sort of message that haskell-cafe does not normally contain. Let's not start now. This is a civilized mailing list. Either comment on the nice gentlemen's PHP closure proposal from a language point of view, or don't say anything. Jules Hear, hear... Paul: You can shut up too, you bloody troll! ___ 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?
At 18:17 18/06/2008, you wrote: 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? :-) Paul: So, now I am silly! I'd still prefer that to a coward and a hypocrite ___ 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?
Blimey! Talk about rearranging the deckchairs :-) With respect, do you not think it'd be wiser for the community to deal with a total lack of proper type checking, the lack of any notion of the general concept of a function, or a whole range of other fundamental issues in PHP first before worrying about closures and lambda functions? I'm no language purist but PHP really does take the biscuit. My personal views and not in any way representing the list . Paul At 17:45 17/06/2008, you wrote: Hi, The PHP community is discussing the adding of closures and lambdas to the language, see the proposal at http://wiki.php.net/rfc/closures If someone with knowledge of both languages could take a quick look it would be great. Thanks a lot Karoly Negyesi Ps. I am not a member of the PHP internals team, I am just a PHP developer but I am very very interested in getting these in my favourite language. ___ 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] Lambda and closures in PHP -- could someone please comment?
But all the cool kids have em! Seriously though computer languages are about getting things done. If this gets more things done for the PHP community in ways easier/simpler/faster than before then it's a win. nerve gas would sort out the problem with mice in our building too, easier simpler faster than the stupid traps. They are after all /their/ deckchairs to play with. Yes, playing with deckchairs while the ship sinks with that bloody woman singing my Heart Will Go on. -ljr PR Stanley wrote: Blimey! Talk about rearranging the deckchairs :-) With respect, do you not think it'd be wiser for the community to deal with a total lack of proper type checking, the lack of any notion of the general concept of a function, or a whole range of other fundamental issues in PHP first before worrying about closures and lambda functions? I'm no language purist but PHP really does take the biscuit. My personal views and not in any way representing the list . Paul At 17:45 17/06/2008, you wrote: Hi, The PHP community is discussing the adding of closures and lambdas to the language, see the proposal at http://wiki.php.net/rfc/closures If someone with knowledge of both languages could take a quick look it would be great. Thanks a lot Karoly Negyesi Ps. I am not a member of the PHP internals team, I am just a PHP developer but I am very very interested in getting these in my favourite language. ___ 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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] What's NaN?
Hello Why does sqrt (-16) return NaN? What is NaN? Thanks Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Type Coercion
Hi (16 :: Float) is a perfectly legitimate statement although I'm surprised that it's allowed in a type strong language such as Haskell. It's a bit like casting in good old C. What's going on here? Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Maybe a, The Rationale
Paul: What is the underlying rationale for the Maybe data type? It is the equivalent of a database field that can be NULL. Paul: shock, horror! the null value or the absence of any value denoted by null is not really in harmony with the relational model. is it the safe style of programming it encourages/ Yes. Consider C, where this is typically done with a NULL pointer, or Lisp, where you use the empty list, nil. These are perfectly good values in themselves, while Nothing is just Nothing, if you pardon the pun. -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Maybe a, The Rationale
Um, I was encountering and recognizing times when I really needed an out-of-band null, and the pain of representing such in C, shortly after I started serious programming in C (call it 1984-5). Is this really difficult? Paul: Hmm, I'm not quite sure what you're driving at. Me neither. Null pointers, EOF markers, didn't find specified key in some tree, etc. Paul: So much time is wasted on making the thing work even if you have perfectly sound semantics. Still, that's a hundred times more preferable to c++ and its anomalies and contradictions. What was Stroustroup thinking of! :- Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] saner shootout programs
I don't know Haskell very well, but Paul: I'm not racist but . . . :-) even I can tell, looking at, for example, the N-body benchmark, that the Haskell code is probably not type-safe, and the tricks used in it would not be usable in a larger program (see below). The task is essentially a pure computation: take a list of bodies having mass, position and velocity; apply Newton laws at discrete intervals for a large number of times; return new positions and velocities. I could write a C++ procedure that performs this task and have some piece of mind regarding its type correctness, exception safety and functional purity: side effects would be local to the procedure, arguments passed as const or by value, the result returned by value, no type casts or new/delete operators used. On the other hand, the Haskell code makes assumptions about the size of double-precision floats (obviously not type-safe). Further, the simulation is not a pure function. It is often argued that one only needs these dirty tricks in the most time-consuming functions. However, if using imperative programming in these inner loop procedures places them in IO monad, the outer loops (the rest of the program - procedures that call it) will have to go there as well. This makes me doubt the Haskell approach to functional programming. If anyone has a version of the N-body benchmark, where the simulation is a type-safe pure function, I would very much like to see and time it. ___ 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] Maybe a, The Rationale
Paul: Hi folks data Maybe a = Nothing | Just a What is the underlying rationale for the Maybe data type? is it the safe style of programming it encourages/ Something tells me this is going to start a lengthy discussion. :-) Bob: Pure and simple -- it allows you to represent partial functions. Looking up a map will only sometimes find a value, so we either return Nothing, or Just that value. Paul: Would yu like to demonstrate this in an example? Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Maybe a, The Rationale
Paul: Hi folks data Maybe a = Nothing | Just a What is the underlying rationale for the Maybe data type? is it the safe style of programming it encourages/ Something tells me this is going to start a lengthy discussion. :-) Bob: Pure and simple -- it allows you to represent partial functions. Looking up a map will only sometimes find a value, so we either return Nothing, or Just that value. Paul: Would yu like to demonstrate this in an example? Um, I was encountering and recognizing times when I really needed an out-of-band null, and the pain of representing such in C, shortly after I started serious programming in C (call it 1984-5). Is this really difficult? Paul: Hmm, I'm not quite sure what you're driving at. Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Induction (help!)
Paul: okay, da capo: We prove/test through case analysis that the predicate p holds true for the first/starting case/element in the sequence. When dealing with natural numbers this could be 0 or 1. We try the formula with 0 and if it returns the desired result we move onto the next stage. If the formula doesn't work with 0 and so the predicate does not hold true for the base case then we've proved that it's a nonstarter. Well, it might hold for all n = 3. But you're right, if p doesn't hold for the base case, then it doesn't hold for _all_ cases. Paul: I don't understand the point you're contending. We've chosen 0 as our base case and if p(0) doesn't hold then nothing else will for our proof. Granted, you may want to start from 3 or 4 as your base case but we're not doing that here and for all we know forall n = 3 p(n) but this isn't relevant to our proof, surely. Paul: In the inductive step we'll make a couple of assumptions: we'll imagine that p(j). We'll also assume that p holds true for the successor of j - p(j+1). Daniel: No. In the induction step, we prove that IF p(j) holds, THEN p(j+1) holds, too. p(j) is the assumption, and we prove that *given that assumption*, p(j+1) follows. Then we have proved (*) p(j) implies p(j+1), for all j. Paul: No, you haven't proved anything! I'm sorry but your assertion fails to make much sense. Daniel: If we already have established the base case, p(0), we have p(0) and (p(0) implies p(1)) - the latter is a special case of (*) - from that follows p(1). Then we have p(1) and (p(1) implies p(2), again a special case of (*), therefore p(2). Now we have p(2) and (p(2) implies p(3)), hence p(3) and so on. Paul: Then with the help of rules and the protocol available to us we'll try to establish whether the formula (f) gives us f(j) = f(j+1) - f(1) So, we know that the predicate holds for 0 or at least one element. By the way, could we have 3 or 4 or any element other than 0? Daniel: Sure, anything. Start with proving p(1073) and the induction proves p(n) for all n = 1073, it does not say anything about n = 1072. Paul: p(0). Then we set out to find out if p holds for the successor of 0 followed by the successor of the successor of 0 and so forth. However, rather than laboriously applying p to every natural number we innstead try to find out if f(j+1) - f(1) will take us back to fj). I think this was the bit I wasn't getting. The assumptions in the inductive step and the algebraic procedures are not to prove the formula or premise per se. That's sort of been done with the base case. Rather, they help us to illustrate that f remains consistent while allowing for any random element to be succeeded or broken down a successive step at a time until we reach the base/starting element/value. Okay so far? Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Order of Evaluation
Hi (take 4 . map (0)) (f s t) where s = 2 : t t = 3 : s f = zipWith (-) What would be the order of evaluation for the above code? How would I illustrate the evaluation step-by-step? I'm guessing that the code necessitates lazy evaluation and as such it starts with take then it applies f which in turn applies s and t and zipWith until the first element satisfies the predicate in map and This is repeated 4 times What does the list think? Many thanks, Paul P.S. I'm not done with induction. I'm just letting it rst for a bit. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Order of Evaluation
Hi (take 4 . map (0)) (f s t) where s = 2 : t t = 3 : s f = zipWith (-) What would be the order of evaluation for the above code? How would I illustrate the evaluation step-by-step? What do you need it for, really? Pure functional programs are not about evaluation order, but about values. Paul: It actually comes from an old test. The question provides the code, asks for the evaluation of the code and then asks You should show your working at each stage of the calculation. This isn't a straightforward top-to-bottom calculation that you can carry out in the style demonstrated frequently in the Hutton book. - {apply bla bla } So I'm wondering how else it can be done. Many thanks Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] (Num t) = [t] or [Int]
Hi I thought [1, 2, 3] :: [Int] GHC says it's (Num t) [t] Okay, when it comes to 3.3:[1,2,3] (Num t) = [t] makes more sense. Is that the only reason? Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] inserting values in a binary tree
Hi data Ord a = Tree a = Nil | Node (Tree a) a (Tree a) How would one go about inserting a value in a binary search tree of the above description? Cheers Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: inserting values in a binary tree
Actually, you've touched an important point there. It's balancing that I'm having difficulty with. Paul At 23:46 09/05/2008, you wrote: PR Stanley [EMAIL PROTECTED] wrote: Hi data Ord a = Tree a = Nil | Node (Tree a) a (Tree a) How would one go about inserting a value in a binary search tree of the above description? Using a library ;) Inserting isn't the problem, balancing is where things get interesting: have a look at http://en.wikipedia.org/wiki/AVL_tree -- (c) this sig last receiving data processing entity. Inspect headers for past copyright information. All rights reserved. Unauthorised copying, hiring, renting, public performance and/or broadcasting of this signature prohibited. ___ 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] Induction (help!)
You've got the right idea. Paul: At long last! :-) I should point out that it doesn't make sense to say p(Succ n) = Succ(p(n)), p(x) represents some statement that is either true or false, so it doesn't make sense to say Succ(p(n)). . Paul: okay, da capo: We prove/test through case analysis that the predicate p holds true for the first/starting case/element in the sequence. When dealing with natural numbers this could be 0 or 1. We try the formula with 0 and if it returns the desired result we move onto the next stage. If the formula doesn't work with 0 and so the predicate does not hold true for the base case then we've proved that it's a nonstarter. In the inductive step we'll make a couple of assumptions: we'll imagine that p(j). We'll also assume that p holds true for the successor of j - p(j+1). Then with the help of rules and the protocol available to us we'll try to establish whether the formula (f) gives us f(j) = f(j+1) - f(1) So, we know that the predicate holds for 0 or at least one element. By the way, could we have 3 or 4 or any element other than 0? Anyway, p(0). Then we set out to find out if p holds for the successor of 0 followed by the successor of the successor of 0 and so forth. However, rather than laboriously applying p to every natural number we innstead try to find out if f(j+1) - f(1) will take us back to fj). I think this was the bit I wasn't getting. The assumptions in the inductive step and the algebraic procedures are not to prove the formula or premise per se. That's sort of been done with the base case. Rather, they help us to illustrate that f remains consistent while allowing for any random element to be succeeded or broken down a successive step at a time until we reach the base/starting element/value. Okay so far? Cheers Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Induction (help!)
Hi One of you chaps mentioned the Nat data type data Nat = Zero | Succ Nat Let's have add :: Nat - Nat - Nat add Zero n = n add (Succ m)n = Succ (add m n) Prove add m Zero = m I'm on the verge of giving up on this. :-( Cheers Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Induction (help!)
So, when you apply the function to the first element in the set - e.g. Zero or Nil in the case of lists - you're actually testing to see the function works. Then in the inductive step you base everything on the assumption that p holds for some n and of course if that's true then p must hold for Succ n but you have to prove this by taking Succ from n and thus going bakc to its predecessor which is also the hypothesis p(n). So, to reiterate assumption: if hypothesis then conclusion if p(n) then p(Succ n) proof of assumption if p(Succ n) = Succ(p(n)) then we've won. If pn+1) = p(n) + p(1) then we have liftoff! I'm not going to go any further in case I'm once again on the wrong track. Cheers Paul At 22:43 07/05/2008, you wrote: On Wed, May 7, 2008 at 9:27 PM, PR Stanley [EMAIL PROTECTED] wrote: Hi One of you chaps mentioned the Nat data type data Nat = Zero | Succ Nat Let's have add :: Nat - Nat - Nat add Zero n = n add (Succ m)n = Succ (add m n) Prove add m Zero = m To prove this by induction on m, you would need to show: 1) add Zero Zero = Zero 2) If add m Zero = m, then add (Succ m) Zero = Succ m Number (1) is completely trivial, nothing more needs to be said. (2) is easy, after expanding the definition. Here the P I used was P(x) := add m Zero = m, the thing we were trying to prove. (1) is a base case, P(Zero). (2) is the inductive step, If P(m) then P(Succ m). Hoping I don't sound patronizing: if you're still having trouble, then I suspect you haven't heard what it means to prove an if-then statement. Here's a silly example. We want to prove: If y = 10, then y - 10 = 0. First we *assume* the condition of the if. We can consider it true. Assume y = 10. Show y - 10 = 0. Well, y = 10, so that's equivalent to 10 - 10 = 0, which is true. Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Induction (help!)
Hi I don't know what it is that I'm not getting where mathematical induction is concerned. This is relevant to Haskell so I wonder if any of you gents could explain in unambiguous terms the concept please. The wikipedia article offers perhaps the least obfuscated definition I've found so far but I would still like more clarity. The idea is to move onto inductive proof in Haskell. First, however, I need to understand the general mathematical concept. Top marks for clarity and explanation of technical terms. Thanks Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Induction (help!)
Hi I don't know what it is that I'm not getting where mathematical induction is concerned. This is relevant to Haskell so I wonder if any of you gents could explain in unambiguous terms the concept please. The wikipedia article offers perhaps the least obfuscated definition I've found so far but I would still like more clarity. The idea is to move onto inductive proof in Haskell. First, however, I need to understand the general mathematical concept. Top marks for clarity and explanation of technical terms. Thanks Paul Induction - from the small picture, extrapolate the big Deduction - from the big picture, extrapolate the small Thus, in traditional logic, if you induce all apples are red, simple observation of a single non-red apple quickly reduces your result to at least one apple is not red on one side, all others may be red, i.e, you can't deduce all apples are red with your samples anymore. Paul: surely, you wouldn't come up with an incorrect premise like all apples are red in the first place. Sorry, still none the wiser Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Induction (help!)
After you grok induction over the naturals, you can start to think about structural induction, which is usually what we use in programming. They are related, and understanding one will help you understand the other (structural induction actually made more sense to me when I was learning, because I started as a programmer and then became a mathematician, so I thought in terms of data structures). Paul: I was hoping that understanding the classic mathematical concept would help me appreciate the structural computer science) variation better. I don't know what it is about induction that I'm not seeing. It's so frustrating! Deduction in spite of the complexity in some parts makes perfect sense. This, however, is a different beast! So let's say you have a tree, and we want to count the number of leaves in the tree. data Tree = Leaf Int | Branch Tree Tree countLeaves :: Tree - Int countLeaves (Leaf _) = 1 countLeaves (Branch l r) = countLeaves l + countLeaves r We want to prove that countLeaves is correct. So P(x) means countLeaves x == the number of leaves in x. Paul: By 'correct' presumably you mean sound. First we prove P(Leaf i), since leaves are the trees that have no subtrees. This is analogous to proving P(0) over the naturals. Paul: I'd presume 'proof' here means applying the function to one leaf to see if it returns 1. If I'm not mistaken this is establishing the base case. countLeaves (Leaf i) = 1, by definition of countLeaves. Leaf i has exactly one leaf, obviously. So countLeaves (Leaf i) is correct. Now to prove P(Branch l r), we get to assume that P holds for all of its subtrees, namely we get to assume P(l) and P(r). Paul: How did you arrive at this decision? Why can we assume that P holds fr all its subtrees? You can think of this as constructing an algorithm to prove P for any tree, and we have already proved it for l and r in our algorithm. Paul: Is this the function definition for countLeaves? This is analogous to proving P(n) = P(n+1) in the case of naturals. Paul:I thought P(n) was the induction hypothesis and P(n+1) was the proof that the formula/property holds for the subsequent element in the sequence if P(n) is true. I don't see how countLeaves l and countLeaves r are analogous to P(n) and P(n+1). So: Assume P(l) and P(r). P(l) means countLeaves l == the number of leaves in l P(r) means countLeaves r == the number of leaves in r countLeaves (Branch l r) = countLeaves l + countLeaves r, by definition. And that is the number of leaves in Branch l r, the sum of the number of leaves in its two subtress. Therefore P(Branch l r). Now that we have those two cases, we are done; P holds for any Tree whatsoever. In general you will have to do one such proof for each case of your data structure in order to prove a property for the whole thing. At each case you get to assume the property holds for all substructures. Generally not so many steps are written down. In fact in this example, most people who do this kind of thing a lot would write straightforward induction, and that would be the whole proof :-) The analogy between structural induction and induction over the naturals is very strong; in fact induction over the naturals is just induction over this data structure: data Nat = Zero | Succ Nat Hope this helps. Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Non-Overlapping Patterns
Hi isZero :: Int - Bool isZero 0 = True isZero n | n /= 0 = False The order in which the above equations appear makes no difference to the application of isZero. Does the Haskell interpreter rewrite patterns into one single definition using some sort of switch or if construct? Why does an equation without a guard have to be placed after the more specific cases?To put it another way, why doesn't the interpreter identify the more specific cases and put them before the general ones. Cheers Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] unapplying function definitions?
Hi What on earth is unapplying function definitions? The following is taken from chapter 13 of the Hutton book: ...when reasoning about programs, function definitions can be both applied from left to right and unapplied from right to left. Cheers Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] unapplying function definitions?
Hi What on earth is unapplying function definitions? The following is taken from chapter 13 of the Hutton book: ...when reasoning about programs, function definitions can be both applied from left to right and unapplied from right to left. Well, because of referential transparency, we can say that the left hand side of a function is exactly equal to the right hand side. Thus, we can instead of applying functions, and making progress towards a normal form, unapply them and get further away from a normal form... for example: 5 = head [5,6,7,8,9] = head ([5,6] ++ [7] ++ [8,9]) = head (([] ++ [5] ++ [6]) ++ [7] ++ [8,9]) ... There are of course an infinite number of ways of doing this, so it's usually only interesting, if we have some reason for applying a specific expansion. What is the normal form? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Function Type Calculation (Take 2)
Just in case anyone missed this: [1] funk f x = f (funk f) x f :: a x :: b funk f x :: c therefore funk :: a - b - c RHS f (funk f) x :: c f (funk f) :: d - c x :: d f :: e - d - c funk :: h - e f :: h unification f :: a = h = (e - d - c) x b = d No. x :: b = d (a typo?) Paul: What's wrong with x being of type b and of type d? Could you perhaps explain the error please? Don't forget also that funk :: a - b - c = h - e, which means that e = b - c Paul: is that something to do with partial application? (funk f) is a partially applied function, correct? Again an explanation would be appreciated. therefore funk :: ((h - e) - b - c) - b - c No. I don't understand where you've got this expression from. It's funk :: a - b - c = (e - d - c) - b - c = ((b - c) - b - c) - b - c According to GHCi: Prelude let funk f x = f (funk f) x Prelude :t funk funk :: ((t1 - t) - t1 - t) - t1 - t which is about the same. Thanks Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Function Type Calculation (Take 2)
[1] funk f x = f (funk f) x f :: a x :: b funk f x :: c therefore funk :: a - b - c RHS f (funk f) x :: c f (funk f) :: d - c x :: d f :: e - d - c funk :: h - e f :: h unification f :: a = h = (e - d - c) x b = d No. x :: b = d (a typo?) Paul: What's wrong with x being of type b and of type d? Could you perhaps explain the error please? Don't forget also that funk :: a - b - c = h - e, which means that e = b - c Paul: is that something to do with partial application? (funk f) is a partially applied function, correct? Again an explanation would be appreciated. therefore funk :: ((h - e) - b - c) - b - c No. I don't understand where you've got this expression from. It's funk :: a - b - c = (e - d - c) - b - c = ((b - c) - b - c) - b - c According to GHCi: Prelude let funk f x = f (funk f) x Prelude :t funk funk :: ((t1 - t) - t1 - t) - t1 - t which is about the same. Thanks Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Function Type Calculation (Take 2)
In case you missed it the first time here is my query again: Hi I know we've already looked at the topic of function type calculation though last time I didn't have the chance to go through it thoroughly. So here it is again. Apologies for the repetition. I've had a try at calculating function types for two examples below. So to start with I'd be grateful for an assessment of my efforts. All comments are welcome. Thanks, Paul [1] funk f x = f (funk f) x f :: a x :: b funk f x :: c therefore funk :: a - b - c RHS f (funk f) x :: c f (funk f) :: d - c x :: d f :: e - d - c funk :: h - e f :: h unification f :: a = h = (e - d - c) x b = d therefore funk :: ((h - e) - b - c) - b - c [2] w f = f f Assigning Types f :: a w f :: b therefore w :: a - b RHS f f :: b f :: c - b f :: c f :: a = b = c = (c - b) therefore w :: (a - a) - a ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Function Type Calculation (revisited)
Hi I know we've already looked at the topic of function type calculation though last time I didn't have the chance to go through it thoroughly. So here it is again. Apologies for the repetition. I've had a try at calculating function types for two examples below. So to start with I'd be grateful for an assessment of my efforts. All comments are welcome. Thanks, Paul [1] funk f x = f (funk f) x f :: a x :: b funk f x :: c therefore funk :: a - b - c RHS f (funk f) x :: c f (funk f) :: d - c x :: d f :: e - d - c funk :: h - e f :: h unification f :: a = h = (e - d - c) x b = d therefore funk :: ((h - e) - b - c) - b - c [2] w f = f f Assigning Types f :: a w f :: b therefore w :: a - b RHS f f :: b f :: c - b f :: c f :: a = b = c = (c - b) therefore w :: (a - a) - a ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[4]: [Haskell-cafe] deriving
Hello Hans, Tuesday, April 8, 2008, 12:17:38 PM, you wrote: deriving which I think is not used elsewhere. It will break a lot of code, but it is easy to change, and also easy to make a compatibility mode. it's also easy to replace all the books, update all code repositories and reteach all the programmers if you ready to pay for it all :D I'm sure you could introduce change gradually without too much pain. I personally think deriving is a descriptive term, now that I understand its role better. I suppose you could consider specialize or instanciate but both those terms are very closely associated with OO and deriving an instance of a class with a type isn't quite like instantiation or even specialisation. We want a single word which is equivalent to derives from. Deriving by itself can seem a bit ambiguous at first. Cheers Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] What's the difference?
Hi What is the difference between data T0 f a = MkT0 a instance Eq (T0 f a) where ... and data T0 f a = MkT0 a instance Eq a = Eq (T0 f a) where ... I've only seen the = operator used for declaring extended classes but never with class instances. By the way, what is the correct terms for the = and the -? Cheers Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What's the difference?
What is the difference between data T0 f a = MkT0 a instance Eq (T0 f a) where ... and data T0 f a = MkT0 a instance Eq a = Eq (T0 f a) where ... The second one says that TO f a is only an instance of Eq if a is, while the first says that TO f a is an instance regardless of the type of its arguments. More explanation please. :-) Much obliged, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] The range operator
At 12:28 07/04/2008, you wrote: On Fri, Apr 4, 2008 at 10:49 PM, Andrew Coppin [EMAIL PROTECTED] wrote: More to the point, the range y..z goes in steps of y-z. ;-) [x,y..z] goes in steps of y-x ;-), [y..z] goes in steps of 1 (depending on the type). Could you elaborate please? ___ 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
[Haskell-cafe] deriving
Hi data Bool = False | True deriving (Eq, Or, Show, Read) Bool is an instance of Eq, Ord, Show and Read. It is derived form these classes. If that is the meaning of the keyword deriving then wouldn't a different keyword such as from or derivative or even derivation be closer to the semantics of the concept? Discuss :-) Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] deriving
Hi data Bool = False | True deriving (Eq, Or, Show, Read) Bool is an instance of Eq, Ord, Show and Read. It is derived form these classes. If that is the meaning of the keyword deriving then wouldn't a different keyword such as from or derivative or even derivation be closer to the semantics of the concept? Discuss :-) Cheers, Paul I'm not getting it. Are you thinking that Bool itself is derived from these classes, rather than those four instances for Bool? - Conal Paul: I am aware that Bool is an instance of Eq, Ord, ... What I'm not sure about is the terminology used here. Deriving, deriving what from Eq, Ord, ...? How about data Bool = False | True from (Eq, Ord, Show, Read) although I have a feeling that from is already used somewhere in Haskell. Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] deriving
Hi data Bool = False | True deriving (Eq, Or, Show, Read) Bool is an instance of Eq, Ord, Show and Read. It is derived form these classes. No. deriving ... here does not mean that Bool is derived from those classes; it's not a statement about inheritance or anything similar. deriving ... means that the class instances for Bool, for those four type classes, are automatically derived from the definition of Bool. Does this make more sense? No, sorry. I'm not sure how this differs from my definition. Could you elaborate please? Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] deriving
Hi, Thank you very much for your helpful replies. So, we define (or is it declare) a class with a polymorphic value(s which will be used in defining function types or functions associated with that class. The data types are then used for deriving instances of that class specific to each data type. The function defined in the general class can be redefined if necessary. It sort of reminds me of specialisation in OO. Get thee behind me beast. :-) Any comments? Cheers, Paul At 20:05 07/04/2008, you wrote: Paul, No, sorry. I'm not sure how this differs from my definition. Could you elaborate please? Gladly. I haven't tested any of the code below, so pardon any typos and thinkos. It sounded like you were trying to say that Bool derives from Eq, Ord, Show, and Read, and thus the keyword from would apply. Of course, I may have misunderstood your intent. I was countering by saying that the deriving keyword indicates something different. I'll try to describe what I meant in a little more detail. A type class definition defines properties of the type class. Eg., class Example a where foo :: a bar :: a - a The class is then related to specific types by giving them instance declarations. The instance declarations can be explicit, as in data Xyzzy = Xy | Zzy instance Example Xyzzy where foo = Xy bar = const Zzy Sometimes the instance declaration can be automatically derived instead, which looks like: data Xyzzy = Xy | Zzy deriving (Example) This lets the compiler derive the obvious class instance declaration. But it won't work for just any class, because the compiler needs to know how to derive obvious instances. A few classes have deriving machinery built-in: Eq, Ord, Enum, Bounded, Show, Read. deriving (Example) won't work, since that machinery doesn't exist. With effort, you could implement this automatic derivation machinery for your own types, at least in GHC. I've never needed it, so I've never learned exactly how to do it. In short, so data Foo [...] deriving (Eq) means: define a new type Foo, and automatically derive its class instance for Eq. Does this help? Regards, John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Windows CE, Xscale Compiler?
I'm surprised you can't use the Glasgow implementation on CE. At 13:55 04/04/2008, you wrote: Is there any Haskell compiler for Windows CE on a XScale platform? I googled around a bit and found references to a Hugs implementation but couldn't find any place to download it. I have the opportunity to program a teledrive[1] and would very much like to avoid something disfunctional like C. [1] http://www.iavproducts.com/de/produkte/teledrive/teledrive.php ___ 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] Windows CE, Xscale Compiler?
At 14:37 04/04/2008, you wrote: And how would I cross compile something for that platform with ghc? (There seems to be no port, which is fine) Don't look at me mate. :-) PR Stanley schrieb: I'm surprised you can't use the Glasgow implementation on CE. At 13:55 04/04/2008, you wrote: Is there any Haskell compiler for Windows CE on a XScale platform? I googled around a bit and found references to a Hugs implementation but couldn't find any place to download it. I have the opportunity to program a teledrive[1] and would very much like to avoid something disfunctional like C. [1] http://www.iavproducts.com/de/produkte/teledrive/teledrive.php ___ 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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] The range operator
Hi folks [x, y..z] What's the role of x? Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Precedence (Part 2)
Hi folks let f = sum.map (^2).filter even f [1..4] 20 So far so good! sum.map (^2).filter even [1..4] returns an error. How is it that the composition above as part of a function equation doesn't return any errors while on its own it requires parentheses? I can understand the need for the parentheses - the composition operator takes two arguments/operand,s each of which is a mapping which must correspond to specific domain and range requirements i.e. (b-c - (a-b) - (a-c) Why aren't the parentheses required in the function definition? Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Precedence (Part 2)
Hi folks let f = sum.map (^2).filter even f [1..4] 20 So far so good! sum.map (^2).filter even [1..4] returns an error. How is it that the composition above as part of a function equation doesn't return any errors while on its own it requires parentheses? You seem to have expression evaluation confused with cpp/m4 macros. The `f' in `f [1..4]' is not expanded as text to `sum.map (^2).filter even [1..4]'; it is evaluated as a function whose definition will (when needed! lazy language) eventually turn out to be `sum.map (^2).filter even'. If you really must view it as a text macro substitution, then imagine that every macro expansion has a set of parentheses added around it. -- Okay, so it's not expanded like a CPP macro. How is it evaluated? What happens to the sum.map ... definition if it's not simply used to substitute f? Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Function Precedence
Hi If f x = x and g y = y then f g x returns an error because f takes only one argument. Why can't we have function application implemented outwardly (inside-out). So f g x would be applied with gx first followed by its return value passed to f instead of putting g x in brackets. Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] function type def
HI It's one of those things - I know sort of instinctively why it is so but can't think of the formal rationale for it: f g x = g (g x) :: (t - t) - (t - t) Why not (t - t) - t - (t - t) to take account of the argument x for g? Cheers Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Function Precedence
Think about this: map (+1) [1..10] What should it do? take (+1) and return a function which takes a list as its argument and finally return a list. How about: f 1 2 3 Should that be f (1 (2 3)), or ((f 1) 2) 3? The latter, of course, but that's not really what I'm driving at. I'm asking why we can't have a function treated differently with regard to the precedence and associativity rules. f 1 2 is indeed ((f 1) 2). Why not f 1 g 2 == ((f 1) (g 2))? Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Function Precedence
Are you asking why one doesn't change the rules for all functions? Or are you asking why Haskell doesn't include a system of user-defined precedence and associativity for function application so that one could declare that g binds more tightly than f? I see good reasons for both questions, but I'm unsure which you mean. In both cases, it comes down to consistency of the syntax rules. In order for (f 1 g 2) to parse as (f 1) (g 2), one would have to do something surprising. It's unclear what that is: perhaps treat literals differently from variables? Somehow determine a precedence level for (f 1)? Or maybe favor shorter argument lists for grouping function application? If you have a very clear kind of grouping that you think makes sense in all cases, feel free to mention it. It seems unlikely to me, but perhaps everyone will agree, once they see it, that it is in fact better than the current parsing rules. Paul: All you'd have to do is to give the inner most function the highest precdence therefore f g x == f (g x) let f x = x^2 let g x = x`div`2 f g 4 == error while f (g 4) == 4 I'm beginning to wonder if I fully understand the right associativity rule for the - operator. Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] function type def
Try putting this through your GHCI: :t twice f x = f (f x) I'd presume that based on the inference of (f x) f is (t - t) and x :: t Yes, Maybe I should get the right associativity rule cleared first. Cheers, Paul At 20:35 01/04/2008, you wrote: PR Stanley: I know sort of instinctively why it is so but can't think of the formal rationale for it: f g x = g (g x) :: (t - t) - (t - t) First of all - it is not the definition f g x = ... :: (t- ... but the type of the function which might be specified: f :: (t-t)-t-t Then, the answer to: Why not (t - t) - t - (t - t) to take account of the argument x for g? is simple. If t is the type of x, then g must be g :: t-t, you're right. So f :: (t-t) - t - [the type of the result] But this result is of the type t, it is g(g x), not (t-t), it is as simple as that. Perhaps you didn't recognize that - is syntactically a right-associative op, so a-b-c is equivalent to a-(b-c), or (t-t)-t-t equiv. to (t-t)-(t-t) Jerzy Karczmarczuk ___ 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] Bay Area talk tomorrow, on concurrent/parallel Haskell
At 13:23 28/02/2008, you wrote: Hello, I wish I could be there, but I'm in Kentucky. ;) It would be great if someone could have this talk recorded and posted on youtube, or something similar. Thank you. Now, there's an idea which could be extended to all Haskell related gatherings. __ Donnie On 2/27/08, Bryan O'Sullivan mailto:[EMAIL PROTECTED][EMAIL PROTECTED] wrote: Satnam Singh of Microsoft Research will be speaking about concurrent and parallel programming at Stanford tomorrow. Details here: http://www.realworldhaskell.org/blog/2008/02/28/stanford-haskell-talk-2008-02-28/http://www.realworldhaskell.org/blog/2008/02/28/stanford-haskell-talk-2008-02-28/ b ___ Haskell-Cafe mailing list mailto:Haskell-Cafe@haskell.orgHaskell-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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Designing a Parser
Hi friends I'm in the process of designing a series of functions which you might collectively call a parser. The idea is to evaluate an input string for a proof software. So a typical input string would be something like (P Q) - q. There are a number of things to consider here, for example, does the string belong to the domain which is a subset of the 7-bit ASCII table, starting from 32 and ending at 126. Then you need to remove all space characters to make things a bit simpler. Next we find out if the logical sentnece is bracketted. I start this by looking for a bracket in the string. If true then I isolate the brackets into a new set in order to spot any odd ones. Here is what I've done so far: domain :: [Char] domain = [x | x - ascii7, x = ' ' x = '~'] where ascii7 = ['\0'..'\127'] -- a legal input character is a member of domain. isInDomain :: Char - Bool isInDomain x = any (==x) domain -- a legal input string is a subset of domain. isSubset :: [Char] - Bool isSubset input = all isInDomain input -- delete spaces for easier parsing. noSpace :: [Char] - [Char] noSpace input = [x | x - input, x /= space] where space = ' ' -- set of brackets brackets = ['(', ')', '[', ']', '{', '}'] -- Are there any brackets in input? hasBrackets :: [Char] - Bool hasBrackets input = or [True | x - input, any (==x) brackets] -- filter all brackets into a subset. getBrackets :: [Char] - [Char] getBrackets input = [x | x - input, any (==x) brackets] -- What are matching brackets? areMatched :: Char - Char - Bool areMatched '(' ')' = True areMatched '[' ']' = True areMatched '{' '}' = True areMatched _ _ = False -- Can all the brackets in input be paired up? allMatched :: [Char] - Bool I can't think of an elegant pattern for the last function. I've already tried set comprehension. However, something tells me that the answer may lie in a complex recursive pattern. I'm not afraid of complex solutions but I naturally see them as an easy way out. It's those clear simple patterns that separate men from mice. :-) I'd be grateful for any advice on this and indeed my approach as a whole. If you think I'm on the wrong path from the start feel free to let me know. I'm not asking for the answer. I'd like to work that out by myself although some guidance would be most appreciated. Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Designing a Parser
Actually, I haven't sent this question to the list before. So you're in no danger of repeating yourself. Thanks for your kind reply anyway Paul At 07:03 17/02/2008, you wrote: On Feb 17, 2008 6:20 AM, PR Stanley [EMAIL PROTECTED] wrote: I can't think of an elegant pattern for the last function. I've already tried set comprehension. However, something tells me that the answer may lie in a complex recursive pattern. I'm not afraid of complex solutions but I naturally see them as an easy way out. It's those clear simple patterns that separate men from mice. :-) I'd be grateful for any advice on this and indeed my approach as a whole. If you think I'm on the wrong path from the start feel free to let me know. I'm not asking for the answer. I'd like to work that out by myself although some guidance would be most appreciated. Yes, I definitely think you're on the wrong path from the start. In high school when I was learning C++ I wrote an arithmetic expression parser in something like this fashion. I scanned the input for the first opening bracket, then I walked forward to the matching closing bracket and extracted the subexpression and evaluated it. The approach turned out to be both complicated and inefficient. I think the biggest problem was that it didn't scale well with implementation complexity; eg. to add support for prefix functions like sin() was almost impossible. Think about how you would go about doing such things using your approach. I think I've seen you ask questions relating to this on the list before, and at the risk of repeating others, I suggest the ReadS in the Haskell Prelude. You get the benefit of it being a clean, top-down solution as well as the benefit of having a lot of primitive Haskell types already implemented for you (such as Integers). I'll describe the approach again, describing the combinators, and then afterward showing how you might use them to accomplish this problem. I'll leave the details up to you, since you can learn a lot by implementing combinator libraries like this. First, you build a bunch of functions which are parsers. A parser is just a function of type String - [(a,String)] for some type 'a'; that is, it takes a string and returns a list of parses, where a parse is the value parsed paired with the remainder of the string. So if you have a function: parseInt :: String - [(Int,String)] Then you can expect this result: parseInt 123 hello world = [(123, hello world)] Or maybe even: parseInt 123 hello world = [(123, hello world), (12, 3 hello world), (1, 23 hello world)] But that latter behavior is not recommended in this case (i.e. it is advisable force int parsing to be greedy). Then to combine parsers you can use some combination operations: sequenceParsers :: (String - [(a,String)]) - (a - String - [(b, String)]) - String - [(b,String)] That one may be easier to see if you use the built-in type synonym ReadS a = String - [(a, String)]: sequenceParsers :: ReadS a - (a - ReadS b) - ReadsB The second argument here is a function, because we have already parsed the first argument and know its value, so the second argument ought to be able to use it. We can also write: alternateParsers :: ReadS a - ReadS a - ReadS a Which gives all valid parses that the first one recognizes concatenated with all valid parsers that the second one recognizes. Implementation of these combinators is left to you. Since the types of these functions are quite general, you can use a type-directed approach (i.e. if your implementation uses all available data and it typechecks, it's probably correct). Now that you have these, how do you use them to actually parse something? Let's parse simple logical expressions. First we need a data structure to parse into: data Exp = Variable String | AndExp Exp Exp | OrExp Exp Exp Let's do it with a top down coding strategy: write a function to parse an expression using whatever helper functions we need but haven't written yet :-) parseExp :: ReadS Exp parseExp = parseAnyOf [ parseVariable, parseAndExp, parseOrExp ] Where we haven't written parseAnyOf yet. Write that inductively on the list: parseAnyOf :: [ReadS a] - ReadS a parseAnyOf [] = \input - [] parseAnyOf (p:ps) = alternateParsers p (parseAnyOf ps) And jump in to the next thing we haven't written, parseVariable: parseVariable :: ReadS Exp parseVariable = mapParser Variable parseString mapParser doesn't actually parse anything, it just parses whatever its argument does and applies a function to the result: mapParser :: (a - b) - ReadS a - ReadS b mapParser :: (a - b) - (String - [(a,String)]) - String - [(b,String)] I rewrote the type signature to help guide your implementation. That should get you started, and show you how the approach usually goes. You seem to already get the idea of writing many small functions and composing them together
[Haskell-cafe] set terminology
Hi domain, source --- are the two different things? I'm sure I read somewhere that the source \subseteq domain in mappings. The same was said about range and target -- target \subseteq range. Any ideas? Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Slightly Offtopic in Part
Hi folks The disjunction elimination rule: I've been trying to make sense of it and I think I have had some success; however, it's far from adequate. I wonder, is there a way of demonstrating it in Haskell? A code frag with a jargon-free explanation would be mucho appreciated. Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] User groups meeting all over the world
I will only consider events where they serve free tea and sandwiches, plus if there's a landing pad for the chopper nearby. :-) At 23:11 07/02/2008, you wrote: The community might be interested to know that there are (at least) 7 Haskell/FP user groups meeting across the world in the next two weeks! FringeDCWashington DC/USAFebruary 9 PDXFunc Portland/USA February 11 Fun in the afternoonLondon/UKFebruary 12 BayFP San Francisco/USAFebruary 13 Saint-Petersburg Haskell User Group Saint-Petersburg/Russia. February 16 NYFP NetworkNew York/USA February 19 NWFPIG: Seattle FP GroupSeattle/USA February 20 The Austin (Texas) group met a couple of weeks ago. This is a great development -- a year ago I don't think we had *any* groups meeting regularly. Consider dropping in to one, if there's a meetting near you, or starting your own group! All groups we know about are listed here: http://www.haskell.org/haskellwiki/User_groups -- Don ___ 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
[Haskell-cafe] FP and Quality
Hi folks I'm thinking of writing a little essay arguing the case for the advantages of FP for producing quality software. Can the list recommend any papers/articles which I can use as sources of my argument? I have access to the IEEE database too although earlier I couldn't find anything on the subject. Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FP and Quality
Thanks, keep the tips coming. I like the ones about the type safety and line counts. Cheers, Paul At 23:33 04/02/2008, you wrote: Good luck with this - I'd love to see the outcome. My experience is that FP tends to result in a lot less code, so if there are x bugs per line of code, FP has less bugs per complete application. Talking about haskell, the typesystem dissalows whole classes of bugs. Things simply do not compile if you stitch the innards together in the wrong order (particuarly if you are agressive about using the most general types possible). Since this accounts for perhaps 90% of where I do things wrong in Java, I get a corresponding decrease in run-time bugs in haskell. However, this is somewhat compensated for by the effort needed to get haskell programs through the compiler in the first place - debug at compile or debug at runtime is the tradeoff here. FP is easier to verify mechanically than imperative programming - more of the logic is exposed directly. It's easier to do by-case proofs, even if they are by-hand rather than mechanical. However, all of this is annecdotal. Good luck collecting real stats, or peer-reviewed annecdotes. You may have luck looking at bug-fix times vs number of developers for equivalent FP and Java apps/libs. Worth a shot, given that the bug-trackers tend to be public. You could probably tie it back to the size of the 'fix' patches. Get some nice graphs? Matthew On Monday 04 February 2008, you wrote: Hi folks I'm thinking of writing a little essay arguing the case for the advantages of FP for producing quality software. Can the list recommend any papers/articles which I can use as sources of my argument? I have access to the IEEE database too although earlier I couldn't find anything on the subject. Thanks, Paul ___ 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] anybody can tell me the pronuncation of haskell?
At 16:16 29/01/2008, you wrote: Am Dienstag, 29. Januar 2008 02:25 schrieb Tim Chevalier: On 1/28/08, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Well, unless you are French. Then you don't pronounce H. The remaining letters are pronounced according to the Règlements de l'Académie. Fair enough. I wouldn't want to be culturally insensitive, and should have said that my statement was only directed at people who were speaking some dialect of English. Hmm, since Haskell is an English word, it should be pronounced the English way. At least, I try to not pronounce it like a German word [ ] I didn't know Haskell was an English name. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Evolutionary Computing
Hi What does the list think of EC? Genetic algorithm is apparently the latest thing. Is EC mathematically reasonable? Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Computer Science Books using Haskell
Hi Can the list recommend books that use Haskell - or any FP language but preferably Haskell - to illustrate the principles of compilers and/or algorithms? I think most of you would understand if I said that I'd prefer FP code instead of funny math symbols that don't translate into ANSI characters with the current OCR technology, unless, of course, you know of a book available in latex code. Rather than rushing straight to Google I thought I'd first draw on the wealth of knowledge that exists on this list. Cheers Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Possible Improvements
That's a very good point. Yes, let's have some detailed explanations accompanied by some good examples. Cheers, Paul At 08:43 03/12/2007, you wrote: I agree that (in this context, beginning learning Haskell) it is a somewhat minor issue. But I disagree that this is something you should ignore until it becomes a problem and I do think that it should be part of learning Haskell. Properly using strictness is an important part of using Haskell. It makes the difference between code that stack overflows and code that doesn't, code that takes 100 seconds and code that takes 10, code that uses 3MB of RAM and code that uses 600. At least the first of these is not, in my mind, the difference between optimized and unoptimized, but rather the difference between correct and incorrect. Writing better code at the beginning is much easier than trying to figure out what the problem is later. Furthermore, writing better code is not more difficult. In this case it merely means adding two characters. Of late, the rules of thumb for this sort of thing are becoming more widely known. Such things need to be instinctively part of how you write code, much like writing code tail-recursively or not using (++) left associatively. It's not that you should immediately know that this is better, but (more strongly) that you should not even think of the worse ways to begin with in many cases. It would be great if someone could exemplify these rules of thumb, e.g. Primitive types such as Int should be strict unless in the three canonical examples X, Y and Z. My strictness radar is still quite poor and I feel I can't make informed decisions on when I need to make something more strict or lazy. -- Johan ___ 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
[Haskell-cafe] Monads
Hi Does the list consider http://en.wikibooks.org/w/index.php?title=Haskell/Understanding_monadsoldid=933545 a reliable tutorial on monads and, if not, could you recommend an onlien alternative please? Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] do
Hi I've probably asked about the do construct, if that's the right label. Unfortunately I'm still not quite sure of its role and more specifically its syntax. Something to do with generators perhaps? A description plus some examples would be most gratefully received. Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] The Opposite of $
Hi According to the Haskell Wikibook the is the opposite of $. The text also oints out that the | can be used as a substitute. I tried using | but to no avail. Is the list au fait with the | operator? Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Possible Improvements
Hi data Tree = Leaf Int | Node Tree Int Tree occurs :: Int - Tree - Bool occurs m (Leaf n) = m == n occurs m (Node l n r) = m == n || occurs m l || occurs m r It works but I'd like to know if it can be improved in any way. Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Sequencing Parsers: a Simple Example
Hi (=) :: Parser a - Parser b - Parser b p = f = \inp - case p inp of [] - [] [(v, out)] - parse (f v) out based on a lot of guesswork, after the mess created by the OCR, I managed to get the above example to work syntactically but is it semantically correct? Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Sequencing Parsers: a Simple Example
PRS: (=) :: Parser a - Parser b - Parser b p = f = \inp - case p inp of [] - [] [(v, out)] - parse (f v) out You probably want: (=) :: Parser a - (a - Parser b) - Parser b p = f = \inp - case parse p inp of [] - [] [(v,out)] - parse (f v) out Assuming that you're following Graham Hutton's book. Note that this definition won't actually compile; you probably need a Monad instance and a newtype to get this to work properly (see http://www.cs.nott.ac.uk/~gmh/Parsing.lhs for a working version of the same code). PRS: That explains it then. [(v, out)] - parse (f v) out caused a type mismatch. Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Editorial error or something meaningful?
Hi taken from ch.8.3 in the Hutton book: Whereas return v always succeeds, the dual parser failure always fails regardless of the contents of the input string: The dual parser failure? Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What is the role of $!?
Hi Thanks for the explanation. I would be grateful for some examples accompanying the text. I will indicate the right places for real life (Haskell code) examples in the paragraphs below: PJ: As I understand it, the distinction is between the mathematical term non-strict and the implementation method of lazy. Non-strict means that reduction (the mathematical term for evaluation) proceeds from the outside in, so if I have (a+(b*c)) then first you reduce the +, then you reduce the inner (b*c). PRS: No problems so far.. PJ: Strict languages work the other way around, starting with the innermost brackets and working outwards. This matters to the semantics because if you have an expression that evaluates to bottom (i.e. an error, exception or endless loop) then any language that starts at the inside and works outwards will always find that bottom value, and hence the bottom will propogate outwards. PRS: You would also get different results - e.g. let a = 3, b = 7, c = 2 therefore 20 = strict ( ( (a+(b*c)) ) therefore 17 = non-strict ( (a+(b*c)) ) or am I misunderstanding the concept? PJ: However if you start from the outside and work in then some of the sub-expressions are eliminated by the outer reductions, so they don't get evaluated and you don't get bottom. PRS: I'm not sure if I fully understand the bottom idea here. I thought it related to the base value in a recursive pattern. For example: f (.) [] = [] f . (x:xs) = x . f xs What's a sub-expression? PJ: Lazy evaluation, on the other hand, means only evaluating an expression when its results are needed (note the shift from reduction to evaluation). So when the evaluation engine sees an expression it builds a thunk data structure containing whatever values are needed to evaluate the expression, plus a pointer to the expression itself. When the result is actually needed the evaluation engine calls the expression and then replaces the thunk with the result for future reference. PRS: A thunk data structure? Again, a example would be nice. PJ: Obviously there is a strong correspondance between a thunk and a partly-evaluated expression. Hence in most cases the terms lazy and non-strict are synonyms. But not quite. For instance you could imagine an evaluation engine on highly parallel hardware that fires off sub-expression evaluation eagerly, but then throws away results that are not needed. In practice Haskell is not a purely lazy language: for instance pattern matching is usually strict (so trying a pattern match forces evaluation to happen at least far enough to accept or reject the match). The optimiser also looks for cases where sub-expressions are *always* required by the outer expression, and converts those into eager evaluation. It can do this because the semantics (in terms of bottom) don't change. Programmers can also use the seq primitive to force an expression to evaluate regardless of whether the result will ever be used. $! is defined in terms of seq. PRS: More examples please. Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What is the role of $!?
Hi Thanks for the response. JCC: In most languages, if you have some expression E, and when the computer attempts to evaluate E it goes in to an infinite loop, then when the computer attempts to evaluate the expression f(E), it also goes into an infinite loop, regardless of what f is. That's the definition of a strict language. PRS: Does that mean that a strict language is also imperative? Either e or f(e) could result in an infinite loop. JCC: In Haskell, this isn't the case ---we can write functions f such that the computation f(E) terminates, even when E does not. (:) is one such function, as are some functions built from it, such as (++); xn ++ ys terminates whenever xn does, even if ys is an infinite loop. This is what makes it easy and convenient to build infinite loops in Haskell; in most strict languages, if you said let fibs = 0 : 1 : zipWith (+) fibs (tail fibs) the language would insist on evaluating fibs before it actually assigned anything to the memory cell for fibs, giving rise to an infinite loop. (For this reason, most strict languages make such definitions compile-time errors). Unfortunately, non-strictness turns out to be a pain in the ass to implement, since it means when the code generator sees an expression, it can't just generate code to evaluate it --- it has to hide the code somewhere else, and then substitute a pointer to that code for the value of the expression. PRS: Is there a kind of strictness applied when the compiler/interpreter sorts the various sub-expressions into little memory compartments indexed with pointers for later evaluation? To put it another way, does lazy evaluation begin with the outer-most expression, the most abstract, and determine what sshould go where in relation to the subsequent inner expressions? For example: takeWhile (20) [0..9] ++ [10..] The compiler determiens at the outset that the result of takeWhile is a list followed by the calculation of the length of that list based on the predicate (20), and then calls ++ which is for all intents and purposes on its own an infinite loop. Is this what happens? This is a very simple example, that's to say, I am aware that the compiler may be faced with a much more complex job of applying lazy evaluation. Nevertheless, I wonder if there are a set of fundamental rules to which the compiler must always adhere in lazy evaluation. JCC: There are a number of clever optimizations you can use here (indeed, most of the history of Haskell compilation techniques is a list of clever techniques to get around the limitations of compiling non-strict languages), but most of them rely on the compiler knowing that, in this case, if a sub- expression is an infinite loop, the entire expression is an infinite loop. This is actually pretty easy to figure out (most of the time), but sometimes the compiler needs a little help. That's where $! (usually) comes in. When the compiler sees (f $ x), it has to look at f to see whether, if x is an infinite loop, f $ x is one as well. When the compiler sees (f $! x), it doesn't need to look at f --- if x is an infinite loop, (f $! x) always is one as well. So, where in (f $ x) the compiler sometimes needs to put the code for x in a separate top-level block, to be called later when it's needed, in (f $! x) the compiler can always generate code for x inline, like a compiler for a normal language would. Since most CPU architectures are optimized for normal languages that compile f(E) by generating code for E inline, this is frequently a big speed-up. PrS: Your description of $! reminds me of the difference between inline functions and ordinary functions in C++ with the former being faster. Am I on the right track? In either case, (f $ x) and (f $! x), lazy evaluation must be applied at a higher level otherwise either instruction could result in an infinite loop. Therefore, is efficiency the only consideration here? If Haskell is a lazy language and $ merely implies lazy evaluation then what's the difference between (f $ x \oplus y) and (f (x \oplus y))? Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] More accessible papers
Hi Peter, Yes, but why don't researchers just publish their TEX file? You can regard that as the source code for generating PDF/PS whatever no? Building a .tex file can be rather hard with packages and what-not, plus quite a few of us use lhst2tex as a preprocessor. It's not impossible, but its not trivial either, and I can't imagine that anyone would use a .tex over a PDF. I would prefer the .tex version any day! Why not have both versions. Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] More accessible papers
also, Latex source code is 100% accessible to screen reader users. Paul You are completely right, 99% of the people will read the PDF, in exactly the same sense that Windows users prefer to download an installable EXE instead of building from source. But nobody here will argue that the *option* to build from source is useful no? So I don't see why this would not apply to compiling tex files into PDF. But I don't know anything about tex, so I can't really say. I'm using Microsoft Word, shame on me! Yes, I really should learn LaTeX though, because writing a lot of math equations in Word is tiresome... Hi Peter, Yes, but why don't researchers just publish their TEX file? You can regard that as the source code for generating PDF/PS whatever no? Building a .tex file can be rather hard with packages and what-not, plus quite a few of us use lhst2tex as a preprocessor. It's not impossible, but its not trivial either, and I can't imagine that anyone would use a .tex over a PDF. If there is a much better format than PDF as generated by the standard class files, it should be the authors creating it, not other people post-processing the tex. Thanks Neil ___ 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] More accessible papers
Why don't you typeset the whole thing in Latex. That way you'll definitely ensure accessibility. Cheers Paul At 19:43 19/11/2007, you wrote: Most research papers have the same layout: two columns per A4 page. They mostly come as PDF or PS. Although this is standard, it is not really accessible for people with people with bad vision, who prefer larger fonts. When you print this, the fonts are rather small. For those people, a reflowable PDF would make much more sense, so they can choose how big the fonts are on screen paper. Also, some of the new epaper devices, such as the Sony Reader or IRex, don't really support the format of these research papers (they become unreadable). Do any of you have ideas how to convert a two column per page PDF/PS to a single larger column per page, and maybe even reflowable PDF? Thanks, Peter ___ 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] What is the role of $!?
Hi okay, so $! is a bit like $ i.e. the equivalent of putting parentheses around the righthand expression. I'm still not sure of the difference between $ and $!. Maybe it's because I don't understand the meaning of strict application. While we're on the subject, what's meant by Haskell being a non-strict language? Cheers Paul At 01:50 15/11/2007, you wrote: On 14 Nov 2007, at 4:32 PM, Shachaf Ben-Kiki wrote: On Nov 14, 2007 4:27 PM, Justin Bailey [EMAIL PROTECTED] wrote: It's: f $! x = x `seq` f x That is, the argument to the right of $! is forced to evaluate, and then that value is passed to the function on the left. The function itself is not strictly evaluated (i.e., f x) I don't believe. Unless you mean f -- which I still don't think would do much -- it wouldn't make sense to evaluate (f x) strictly. Right. (f x) evaluates f and then applies it to x. (f $! x) evaluates x, evaluates f, and then applies f to x. jcc ___ 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
[Haskell-cafe] The percent operator
Hi I understand 2%4 will construct a fraction in Haskell. I've tried this in GHCI but got an error message. Is there such an operator in Prelude and if so how is it applied? Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell and html input elements
Hi What i have in mind is an interactive Haskell app which allows the user to enter text, push buttons, select radio buttons and so on. As I have already done a lot of xhtml coding I thought it might be easier to operate the program entirely via a web browser. However, I'm also interested in the idea of a straightahead MS Windows GUI for my program but dont' really know where to start. Any advice would be most appreciated. Cheers Paul At 17:13 12/11/2007, you wrote: On Nov 12, 2007, at 8:38 AM, PR Stanley wrote: Hi back again! How easy/hard is it to control a haskell program through a web browser? Hi, It depends on exactly how you want to control it, but at least some control is fairly easy. If you simply want to start a batch Haskell program, and see its output as HTML in a browser, you can use the cgi [1] or fastcgi [2] libraries listed on Hackage. If you want slightly more interactivity, it would make sense to write your Haskell program as its own web server (which is actually surprisingly easy) and have it respond to sequences of requests, perhaphs storing intermediate state along the way. Giving something like this a nice GUI on the user side will probably involve writing a certain amount of JavaScript. One example of a program that works this way is HERA [3], which is unfortunately not open-source at the moment, but may be some day. Another potentially useful library is HAppS [4], which abstracts out some of the functionality necessary for web-based applications. Is this sort of thing along the right track, or were you thinking of something else? Aaron [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ cgi-3001.1.5.1 [2] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ fastcgi-3001.0.1 [3] http://haskell.org/haskellwiki/ Haskell_Equational_Reasoning_Assistant [4] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ HAppS-0.8.4 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Brazilian Haskellers ?
Hi brazilian haskellers, Wow! I knew the Haskell community has been growing... but there's a brazillian of us? -- Rich A mini UN, that's us. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] What is the role of $!?
Hi What is the role of $! ? As far as I can gather it's something to do with strict application. Could someone explain what it is meant by the term strict application please? Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Haskell and html input elements
Hi back again! How easy/hard is it to control a haskell program through a web browser? Cheers Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Slightly off-topic
Hi folks Apologies for the off-topic post. If anyone knows anything about the rules of proof by deduction and quantifiers I'd be grateful for some assistance. Much obliged, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Function Types
Hi What are the rules for calculating function types? Is there a set procedure ? Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Function Types
f x = x x :: a f x :: b therefore f :: a - b x = a and x = b therefore a = b therefore f :: a - a Simple mappings are easy to work out. It's the more detailed stuff I'm not sure about. f g x y = g x (y x) Cheers, Paul At 03:15 23/10/2007, you wrote: On 10/22/07, PR Stanley mailto:[EMAIL PROTECTED][EMAIL PROTECTED] wrote: Hi What are the rules for calculating function types? Is there a set procedure ? Thanks, Paul There must be a set procedure, since otherwise the compiler could not function! =) Seriously, though, I'm not exactly sure what you're asking for. Could you maybe provide a few examples of the kind of thing you're asking about? -Brent ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Do you trust Wikipedia?
At 01:48 19/10/2007, you wrote: On Fri, Oct 19, 2007 at 02:45:45AM +0200, [EMAIL PROTECTED] wrote: PR Stanley writes: One of the reasons I'm interested in Wikipedia and Wikibook is because you're more likely to find Latex source code used for typesetting the maths. Latex is the one and only 100% tool right now. A lot of publishers use Latex but try to get anything from them in electronic form. I don't understand you. WHAT YOU WANT? 1. Many articles in Wikipedia typeset math formulae as *images*, you don't really see the LaTeX sources. Some formulae are typed through plain HTML. Don't forget that PR Stanley is blind. Latex page sources are infinitely superior to unadorned images of unknown providence. Stefan I've sent him an email explaining roughly how the screen reader technology works. Unfortunately, Mathml has a long long way before it can be classed as an alternative to Latex. Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Do you trust Wikipedia?
Hi thank you for all your replies. One of the reasons I'm interested in Wikipedia and Wikibook is because you're more likely to find Latex source code used for typesetting the maths. Latex is the one and only 100% tool right now. A lot of publishers use Latex but try to get anything from them in electronic form. I think it'd be easier to find water on Mars. Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] data Bin = Zero | One
Hi data Bin = Zero | One As suggested by someone on this list. It's a really neat idea although I'm wondering how I can apply this to my int to binary function. The Zero or One declaration is saying that Bin is a data type that can hold either a one or a zero. I tried testing this with a very simple Bin - Bin function and the Integral values 0 and 1 but ran into difficulties. Any ideas what I'm doing wrong here? Incidentally, does the general syntax above come from the old BNF notation? Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Do you trust Wikipedia?
Hi Do you trust mathematical materials on Wikipedia? Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Equality Question
Hi is const = id? const 'x' 'y' 'x' id 'x' 'x' Cheers, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] do
Hi do, what's its role? I know a few uses for it but can't quite understand the semantics - e.g. do putStrLn bla bla So, what does do, do? Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] do
Thanks for the very clear explanation. More questions: What is the role of ? How is different to =? I am aware that = is used for sequencing parsers but that's all I know about it. Thanks, Paul At 22:28 13/10/2007, you wrote: On 10/13/07, PR Stanley [EMAIL PROTECTED] wrote: Hi do, what's its role? I know a few uses for it but can't quite understand the semantics - e.g. do putStrLn bla bla So, what does do, do? In this example, do doesn't do anything. do doesn't do anything to a single expression (well, I think it enforces that its return value is a monad...). It's only when you give it multiple expressions that it rewrites them into more formal notation. For example: do putStrLn bla putStrLn blah Will be rewritten into: putStrLn bla putStrLn blah It introduces a block of sequential actions (in a monad), to do each action one after another. Both of these (since they're equivalent) mean print bla *and then* print blah. do also allows a more imperative-feeling variable binding: do line - getLine putStr You said: putStrLn line Will be rewritten into: getLine = (\line - putStr You said: putStrLn line) Looking at the do notation again: execute getLine and bind the return value to the (newly introduced) variable 'line', then print You said: , then print the value in the variable line. You can think of the last line in the block as the return value of the block. So you can do something like: do line - do putStr Say something: getLine putStr You said: putStrLn line In this example it's kind of silly, but there are cases where this is useful. Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] more functions to evaluate
Hi folks Any comments and/or criticisms no matter how trivial on the following please: wordSize :: [Int] - Int wordSize xs = head (dropWhile ((length xs)) $ iterate (*2) 8) intToBinWord :: Int - [Int] intToBinWord n = reverse (take elements (xs ++ repeat 0)) where xs = reverse (intToBin n) elements = wordSize xs Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Dual Parser Failure???
Hi failure :: (Parser a) failure = \inp - [] The code might contain some syntax errors and I'd be grateful for any corrections. What is a dual parser failure? Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Defining Tree
Hi I'm reading the chapter on parsers in the Hutton book. The text refers to the data type tree which doesn't seem to be in prelude. So, I was wondering, what would be asuitable tree for a parser? A binary tree perhaps? Are there different types of tree for different parsers? Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Curry and uncurry
No, still no idea! I tried curry f where f :: (Num a) = (a, a) - a and it didn't like it. For some reason I'm finding this a little chalenging. Thanks, Paul At 17:03 03/10/2007, you wrote: On 10/3/07, PR Stanley mailto:[EMAIL PROTECTED][EMAIL PROTECTED] wrote: I didn't even know about the curry and uncurry functions. I'm not looking for the answer but some guidance would be much appreciated. Thanks, Paul You can look at the types without seeing the implementation, too. Just start up GHCI and type: :t curry or :t uncurry Justin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Curry and uncurry
Hi The following is from the Hutton book: Without looking at the standard prelude, define the higher-order library function curry that converts a function on pairs into a curried function, and conversely, the function uncurry that converts a curried function with two arguments into a function on pairs. Hint: first write down the types of the two functions. I didn't even know about the curry and uncurry functions. I'm not looking for the answer but some guidance would be much appreciated. Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe