[Haskell-cafe] ICMP in Haskell (was Elevator pitch for Haskell)
Does it enable you to, say, send raw ICMP packets? AFAIK, Haskell supports TCP, and nothing else. (A while back I wanted to write an automated pinging program. But the only way I could figure out how to do it is to call the OS ping utility and attempt to parse what it writes to stdout. Oh, did I mention that's different on WinNT, WinXP and UNIX?) Andrew, I thought this was relatively straightforward. Look in http://www.haskell.org/networktools/src for multi-threaded versions. Beware I wrote ping and traceroute about 5 years ago. They're pretty much straight from Stevens' book. On the other hand, I quite liked this: sequenceWhile_ :: Monad m = (a - Bool) - [m a] - m () sequenceWhile_ p [] = return () sequenceWhile_ p (x:xs) = x = \c - if (p c) then sequenceWhile_ p xs else return () I'd forgotten about them and I'm not particularly proud of them. I guess I could put them in hackage so that they are at least a starting point for someone. Dominic. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Hackage and GHC 6.8
Ah, this begins to answer my question: there isn't really a plan I would have thought that he first step is to be able to distinguish which of the hackage packages compile under 6.8 - some annotation to the hackage DB? Secondly, is there a dependency graph of the stuff on hackage anywhere? That would identify which order to change packages in (for example the cabal-install package is dependent on exactly one version of the HTTP library). We need to size the problem. Nei On 09/09/2007, Duncan Coutts [EMAIL PROTECTED] wrote: On Sat, 2007-09-08 at 14:50 +0100, Neil Mitchell wrote: Hi Neil, Given that GHC 6.8 is just around the corner and, given how it has re-organised the libraries so that the dependencies in many (most/all) the packages in the hackage DB are now not correct. Is there a plan of how to get hackage DB up to speed with GHC 6.8 ? I think whatever we go with will be deeply painful. Especially given the switch to Cabal configurations comes at the same time, rather than before. Cabal 1.2 is out now and supports configurations and current ghc: http://haskell.org/cabal/download.html Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Hackage and GHC 6.8
Thinking on it more - surely there is enough information from the failed compilations to suggest changes to the cabal files? Feed them back to the developers? My thoughts go this way - people like creating, that's why hackage is beginning to grow. They don't tend to like the packaging issues - they are seen as a distraction the more we can automate this the better, the more quickly the libraries are going to get up to date. As a community we are building a momentum here - let's not derail it by a lack of attention to detail. Neil On 09/09/2007, Neil Davies [EMAIL PROTECTED] wrote: Ah, this begins to answer my question: there isn't really a plan I would have thought that he first step is to be able to distinguish which of the hackage packages compile under 6.8 - some annotation to the hackage DB? Secondly, is there a dependency graph of the stuff on hackage anywhere? That would identify which order to change packages in (for example the cabal-install package is dependent on exactly one version of the HTTP library). We need to size the problem. Nei On 09/09/2007, Duncan Coutts [EMAIL PROTECTED] wrote: On Sat, 2007-09-08 at 14:50 +0100, Neil Mitchell wrote: Hi Neil, Given that GHC 6.8 is just around the corner and, given how it has re-organised the libraries so that the dependencies in many (most/all) the packages in the hackage DB are now not correct. Is there a plan of how to get hackage DB up to speed with GHC 6.8 ? I think whatever we go with will be deeply painful. Especially given the switch to Cabal configurations comes at the same time, rather than before. Cabal 1.2 is out now and supports configurations and current ghc: http://haskell.org/cabal/download.html Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Custom unary operator extension?
I find it unfortunate that one can't (I guess) define custom unary operators in Haskell. Is this correct? If so, is this just because eg (* 100) declares a function that partially applies the * operator, so this syntax disallows unary operators? Could this be fixed by introducing a different syntax for partial operator application? E.g. (? * 100) instead of just (*100)? This would also fix the ambiguity between (-10) as being either the number minus 10 or the subtract by 10' function. Cheers, Peter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] zip, map and zipWith for arrays
Hi all, thanks again for all the responses on the imperative loop question. Here is another questions: I am used to work with map, zip and zipWith, when working with lists, however, I could not find such functions for Arrays. For example, in my Finite Element prototype, I have a function type Dof = Double type TimeInc = Double predictU :: Double - TimeInc - Dof - Dof - Dof - Dof predictU beta dt u u_t u_tt = u + dt*u_t + ((dt**2.0)/2.0)*(1.0 - 2.0*beta ) * u_tt Given 3 equal sized lists un, vn and an of double values [Dof], I apply it with u_est = zipWith3 (predictU beta dt) un vn an I like it's conciseness, but is that efficient? The lists can be very long and correspond to a plain C++ vectors in corresponding C++ codes. my own map for a vector I defined based on the Array documention (Data.Array) as mapVec f vec = vec//[ (i, f(vec!i)) |i-[a..b]] where (a,b) = bounds vec I guess, I could implement zip and zipWith in a similar manner, but using list comprehension seems weird and inefficient here. I wonder if these standard functions are already defined somewhere. I only found amap for IArrays http://cvs.haskell.org/Hugs/pages/libraries/base/Data-Array-IArray.html but no zip, zipWith or even zipWith3. The whole point of using (unboxed) Arrays instead of lists is memory performce and speead of random access. Any hints on how to do zipWith on arrays is highly appreciated. Best, Axel Gerstenberger Henning Thielemann schrieb: On Thu, 6 Sep 2007, Axel Gerstenberger wrote: Thanks to all of you. The suggestions work like a charm. Very nice. I still need to digest the advices, but have already one further question: How would I compute the new value based on the 2 (or even more) last values instead of only the last one? [ 2, 3 , f 3 2, f((f 3 2) 3), f ( f((f 3 2) 3) f 3 2)), ...] (background: I am doing explicit time stepping for some physical problem, where higher order time integration schemes are interesting. You advance in time by extrapolating based on the old time step values.) You might be interested in some ideas on how to solve differential equations numerically in an elegant way: http://darcs.haskell.org/htam/src/Numerics/ODEEuler.lhs ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ((a - b) - c) - (a - m b) - m c
On Sun, 9 Sep 2007, Stuart Cook wrote: (Inspired by this[1] reddit thread.) When combining monadic and non-monadic code, I've often wished for a magical combinator of type (Monad m) = ((a - b) - c) - (a - m b) - m c which would let me inject a monadic function into a pure one, then wrap the ultimate result to ensure that no nastiness escapes. If the signature would be (Monad m) = ((a - b) - c) - m (a - b) - m c it would be possible, and the implementation would be 'liftM'/'fmap'. In the Reader monad you can even convert (a - m b) to m (a - b) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
On Sun, 9 Sep 2007, Peter Verswyvelen wrote: I find it unfortunate that one can't (I guess) define custom unary operators in Haskell. Why? What is your application? In fact, alphanumeric identifiers are used as unary operators. Is this correct? If so, is this just because eg (* 100) declares a function that partially applies the * operator, so this syntax disallows unary operators? Could this be fixed by introducing a different syntax for partial operator application? E.g. (? * 100) instead of just (*100)? You can also use special syntax for having unary operators. E.g. (*) :: () - a - a used as ()*100 :-) This would also fix the ambiguity between (-10) as being either the number minus 10 or the subtract by 10' function. There has been a long discussion whether the unary minus belongs to number literals or not. http://www.haskell.org/pipermail/haskell-cafe/2006-September/017941.html I think that the benefits of prefix or postfix symbolic operators were not worth dispensing with the comfortable section syntax. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] zip, map and zipWith for arrays
On Sun, 9 Sep 2007, Axel Gerstenberger wrote: I am used to work with map, zip and zipWith, when working with lists, however, I could not find such functions for Arrays. Since 'Array' is an instance of Functor you can use 'fmap' for applying a function to all elements. For example, in my Finite Element prototype, I have a function type Dof = Double type TimeInc = Double predictU :: Double - TimeInc - Dof - Dof - Dof - Dof predictU beta dt u u_t u_tt = u + dt*u_t + ((dt**2.0)/2.0)*(1.0 - 2.0*beta ) * u_tt Given 3 equal sized lists un, vn and an of double values [Dof], I apply it with u_est = zipWith3 (predictU beta dt) un vn an I like it's conciseness, but is that efficient? The problem with combining array is, that they can not only differ in length, but can also have different start indices. How to handle this generically? The best way to express that two vectors have the same interval of indices is to put them in one array, e.g. Array i (a, b)instead of (Array i a, Array i b) Of course this is not alway possible. The lists can be very long and correspond to a plain C++ vectors in corresponding C++ codes. Lists can still be the better structure for your application if you do not need random access. my own map for a vector I defined based on the Array documention (Data.Array) as mapVec f vec = vec//[ (i, f(vec!i)) |i-[a..b]] where (a,b) = bounds vec You do not need update (//) if you overwrite all elements. (//) generates a new array anyway. Btw. you can obtain all indices of an array by range (bounds vec) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ((a - b) - c) - (a - m b) - m c
On 9/9/07, Henning Thielemann [EMAIL PROTECTED] wrote: If the signature would be (Monad m) = ((a - b) - c) - m (a - b) - m c it would be possible, and the implementation would be 'liftM'/'fmap'. Thanks, that's the kind of insight I was looking for. Hmm. A key distinction between (a - m b) and m (a - b) is that in the latter, the monadic component can't depend on the value given to the function. One of the particular cases I had in mind was an (a - IO b) that reads indexed values from a mutable data structure. It would be possible to convert this to IO (a - b) if you knew ahead of time what reads you needed to do, without inspecting the index argument. Of course, you'd be unable to use the index to restrict the amount of reading necessary, which could be a problem for large structures. If you end up reading most of the values anyway, it might still be worth it. In the Reader monad you can even convert (a - m b) to m (a - b) Quite. In the ((-) r) monad, that's a conversion from (a - r - b) to (r - a - b), which is just flip. I shall have to think about what properties are needed for a conversion from (a - m b) to m (a - b), and what other structures have those properties. Actually, all this talk of m (a - b) reminds me of applicative functors, especially since you mentioned fmap (for vanilla functors) above. More food for thought ... Stuart ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Installation of GLUT package
Loading package OpenGL-2.2.1 ... linking ... done. Loading package GLUT-2.1.1 ... linking ... done. The above message was after you have installed GLUT-2.0, but GHC was still loading GLUT-2.1.1. The later errors were caused by your forced copy of 2.0 lib over the default 2.1.1. I noticed this myself. The problem is, I don't know where to get GLUT-2.1.1. If I look on Hackage [1] and select GLUT from the Graphics category, I am directed to GLUT-2.0. [1] http://hackage.haskell.org/packages/archive/pkg-list.html the messages indicate that you already have GLUT-2.1.1 somewhere, even installed at some point. for the latest sources, http://www.haskell.org/haskellwiki/Opengl should give the correct pointers (btw, the hopengl mailinglist specifically covers these topics and, being low-traffic, has a better chance of reaching Sven, whenever he catches up with haskell-related email). in contrast to the hopengl home page, which is outdated, the link above is on the wiki, and is meant to collect information that usually puzzles new hopengl users. so if one of those who have successfully replaced glut with freeglut on windows (or other platforms) could add instructions to that page, that would be useful. from Ron's log, it appears that simply replacing the dll does not quite work? claus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
Why? What is your application? In fact, alphanumeric identifiers are used as unary operators. Why? Well, why are binary operators allowed and unary operators not? Isn't that some kind of discrimination? In math, many many operators are unary. Haskell allows creating binary operators. So I would understand that Haskell supported neither binary nor unary operators, but prefering one above the other just seems odd. Especially when coming from C++ and C#. My application? I'm teaching basic math to beginning video game programmers, and I wanted to demonstrate the logic operators not, and, or, logical equivalence and implication etc in Haskell, building them from scratch. Since most programmers have symbol-phobia, I wanted to let them play with the symbols for operators, with Haskell. E.g. \/, /\, -- -- == == for or, and, if/then, iff, logical implication, logical equivalence, etc... I cannot do this for the not operator, which is a bit annoying, but it's not a show stopper. You can also use special syntax for having unary operators. E.g. (*) :: () - a - a Nice trick :-) There has been a long discussion whether the unary minus belongs to number literals or not. http://www.haskell.org/pipermail/haskell-cafe/2006-September/017941.html Yes I read it... I think that the benefits of prefix or postfix symbolic operators were not worth dispensing with the comfortable section syntax. Well, that's personal I guess, but I would prefer the syntax (? / 100) and (100 / ?), which is just a single extra character to type, and hence allow unary operators, but hey, that's just me, the newbie ;-) Thanks, Peter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
On Sep 9, 2007, at 9:09 , Peter Verswyvelen wrote: I think that the benefits of prefix or postfix symbolic operators were not worth dispensing with the comfortable section syntax. Well, that's personal I guess, but I would prefer the syntax (? / 100) and (100 / ?), which is just a single extra character to type, and hence allow unary operators, but hey, that's just me, the newbie ;-) I think I'd prefer _ instead of ? there, because it already has the meaning of placeholder. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Hackage and GHC 6.8
are seen as a distraction the more we can automate this the better, I've run into this trouble as well. And libraries will change... or there will be libraries which are not updated etc.. I think another way would be having some automatism in fixing the most obvious things.. Such as if package X does no longer export module y look in the package db which package does and add this instead.. I don't konw how well this will work in practise.. But I'll try when having some time to do so.. Marc ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Tiny documentation request
I have the following page bookmarked: http://haskell.org/ghc/docs/latest/html/libraries/ I'd like to ask 2 things. 1. Would it be possible to make the *huge* list of package names at the top collapsable? (That way I don't have to scroll through several pages of uninteresting text to get to the bit I actually want.) 2. Could we make is so all items are collapsed initially? (Currently they're all expended initially - which makes it take rather a long time to find anything.) Just thought I'd ask... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
On Sun, 9 Sep 2007, Peter Verswyvelen wrote: I find it unfortunate that one can't (I guess) define custom unary operators in Haskell. Incidentally, the nhc98 compiler has always permitted the definition of unary operators, as an extension to the language. (It was just more convenient to create a general mechanism for unary/prefix operators, than to code the special case for negative numbers.) The definition syntax is rather like for infix decls: infixl 6 + prefix negate 6 - -- WARNING Not standard Haskell The operator symbol (-) is bound to a function name (negate), and has a precedence just like infix operators. Regards, Malcolm ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Tiny documentation request
I agree about the top part. It's not very interesting, especially not in a document used as a reference. Perhaps we could move it to the end and provide an anchor link from the different modules down to their package explanation. A tip is to use Firefox's search as you type feature if you know the module name. Cheers, Johan On 9/9/07, Andrew Coppin [EMAIL PROTECTED] wrote: I have the following page bookmarked: http://haskell.org/ghc/docs/latest/html/libraries/ I'd like to ask 2 things. 1. Would it be possible to make the *huge* list of package names at the top collapsable? (That way I don't have to scroll through several pages of uninteresting text to get to the bit I actually want.) 2. Could we make is so all items are collapsed initially? (Currently they're all expended initially - which makes it take rather a long time to find anything.) Just thought I'd ask... ___ 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] Tiny documentation request
On Sunday 09 September 2007 16:40, Andrew Coppin wrote: I have the following page bookmarked: http://haskell.org/ghc/docs/latest/html/libraries/ I'd like to ask 2 things. 1. Would it be possible to make the *huge* list of package names at the top collapsable? (That way I don't have to scroll through several pages of uninteresting text to get to the bit I actually want.) What do you mean exactly with the *huge* list of package names? The description list with the short textual descriptions of each package? I'd say that this list is highly interesting to people unfamiliar with the package structure, so it is good that it is there. 2. Could we make is so all items are collapsed initially? (Currently they're all expended initially - which makes it take rather a long time to find anything.) Again this depends on the use case: I'd vote strongly against collapsing the list initially, because that way the incremental search in Firefox won't work without un-collapsing everything. When the index is generated with a more recent Haddock, you get a search field, which does an incremental search, so this might perhaps be more what you are looking for. A more aesthetical note: We should really get rid of the ugly table/CSS layout mixture, the lower part of the page renders a bit ugly and varies between browsers. Switching to pure CSS should be safe in 2007, I guess. Cheers, S. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
On Sun, 2007-09-09 at 15:09 +0200, Peter Verswyvelen wrote: Why? What is your application? In fact, alphanumeric identifiers are used as unary operators. Why? Well, why are binary operators allowed and unary operators not? Isn't that some kind of discrimination? In math, many many operators are unary. Haskell allows creating binary operators. So I would understand that Haskell supported neither binary nor unary operators, but prefering one above the other just seems odd. Especially when coming from C++ and C#. My application? I'm teaching basic math to beginning video game programmers, and I wanted to demonstrate the logic operators not, and, or, logical equivalence and implication etc in Haskell, building them from scratch. Since most programmers have symbol-phobia, I wanted to let them play with the symbols for operators, with Haskell. E.g. \/, /\, -- -- == == for or, and, if/then, iff, logical implication, logical equivalence, etc... I cannot do this for the not operator, which is a bit annoying, but it's not a show stopper. You can also use special syntax for having unary operators. E.g. (*) :: () - a - a Nice trick :-) There has been a long discussion whether the unary minus belongs to number literals or not. http://www.haskell.org/pipermail/haskell-cafe/2006-September/017941.html Yes I read it... I think that the benefits of prefix or postfix symbolic operators were not worth dispensing with the comfortable section syntax. Well, that's personal I guess, but I would prefer the syntax (? / 100) and (100 / ?), which is just a single extra character to type, and hence allow unary operators, but hey, that's just me, the newbie ;-) With enough insanity simulating infix operators should be no problem, http://www.informatik.uni-bonn.de/~ralf/publications/Quote.pdf ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Tiny documentation request
Sven Panne wrote: On Sunday 09 September 2007 16:40, Andrew Coppin wrote: 1. Would it be possible to make the *huge* list of package names at the top collapsable? (That way I don't have to scroll through several pages of uninteresting text to get to the bit I actually want.) What do you mean exactly with the *huge* list of package names? The description list with the short textual descriptions of each package? I'd say that this list is highly interesting to people unfamiliar with the package structure, so it is good that it is there. Well, if I could collapse it with a single click, it would be much easier to scroll past it and get to the thing I'm looking for. I didn't say remove it, just give me the option to hide it. ;-) 2. Could we make is so all items are collapsed initially? (Currently they're all expended initially - which makes it take rather a long time to find anything.) Again this depends on the use case: I'd vote strongly against collapsing the list initially, because that way the incremental search in Firefox won't work without un-collapsing everything. Oh goodie... So it's there to keep the machines happy? It's just tedious that every single time I load up this page, I have to spend 30 seconds manually collapsing everything so I can get to the module I actually want to look at. (The alternative is to manually scroll the 13-page list my hand. Not very funny...) OK, so... can we add a pair of expand all/collapse all buttons then? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
Brandon S. Allbery KF8NH wrote: On Sep 9, 2007, at 9:09 , Peter Verswyvelen wrote: I think that the benefits of prefix or postfix symbolic operators were not worth dispensing with the comfortable section syntax. Well, that's personal I guess, but I would prefer the syntax (? / 100) and (100 / ?), which is just a single extra character to type, and hence allow unary operators, but hey, that's just me, the newbie ;-) I think I'd prefer _ instead of ? there, because it already has the meaning of placeholder. Indeed, much better! Peter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Tiny documentation request
Hi I have the following page bookmarked: http://haskell.org/ghc/docs/latest/html/libraries/ Just bookmark: http://haskell.org/hoogle It's not perfect, but it probably solves lots of your problems. A tip is to use Firefox's search as you type feature if you know the module name. This will be better supported in Hoogle 4 - but unfortunately degrees etc. are coming in the way of Hoogle development... A more aesthetical note: We should really get rid of the ugly table/CSS layout mixture, the lower part of the page renders a bit ugly and varies between browsers. Switching to pure CSS should be safe in 2007, I guess. Replicating actual tables with CSS is a nightmare - you shouldn't use table's for lots of things, but there are sometimes when it really is the best option. Fixing up the CSS and still keeping tables is a perfectly valid option. Thanks Neil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
Malcolm Wallace wrote: Incidentally, the nhc98 compiler has always permitted the definition of unary operators, as an extension to the language. (It was just more convenient to create a general mechanism for unary/prefix operators, than to code the special case for negative numbers.) Cool! I found it rather ugly that the negation operator was wired-in. It's a petty this is not part of the upcoming Haskell standard, or is it? GHC can't do this right? Peter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
On Sun, 9 Sep 2007, Peter Verswyvelen wrote: Why? What is your application? In fact, alphanumeric identifiers are used as unary operators. Why? Well, why are binary operators allowed and unary operators not? Isn't that some kind of discrimination? In math, many many operators are unary. Haskell allows creating binary operators. So I would understand that Haskell supported neither binary nor unary operators, but prefering one above the other just seems odd. Especially when coming from C++ and C#. The more syntactic constructs exist, the more complicated it becomes to read such programs. Today, if you read a symbolic operator which is not -, not a single dot with a capital identifier to the left (qualification), not a double dot in a bracket (enumeration) and not enclosed in parentheses (prefix mode), then it is an infix operator. Note the already existing exceptions, and I feel these are not complete. With prefix operators it becomes more difficult. My application? I'm teaching basic math to beginning video game programmers, and I wanted to demonstrate the logic operators not, and, or, logical equivalence and implication etc in Haskell, building them from scratch. Since most programmers have symbol-phobia, I wanted to let them play with the symbols for operators, with Haskell. E.g. \/, /\, -- -- == == for or, and, if/then, iff, logical implication, logical equivalence, etc... I cannot do this for the not operator, which is a bit annoying, but it's not a show stopper. You can also use special syntax for having unary operators. E.g. (*) :: () - a - a Nice trick :-) Even more simpler is enclosing the symbolic operator in parentheses. (-|) :: Bool - Bool use as(-|) False I think that the benefits of prefix or postfix symbolic operators were not worth dispensing with the comfortable section syntax. Well, that's personal I guess, but I would prefer the syntax (? / 100) and (100 / ?), which is just a single extra character to type, and hence allow unary operators, but hey, that's just me, the newbie ;-) It's easy to predict, that people then soon want to write (? * ?), disputing whether it shall mean (\x - x*x) or (\x y - x*y), and you will quickly re-invent lambda notation. See http://www.haskell.org/pipermail/haskell-cafe/2006-July/016683.html It's tempting to want more syntactic sugar, but there are already so much suggestions that I'm afraid, that the resulting language would be as ambiguous as a natural language. http://www.haskell.org/haskellwiki/Syntactic_sugar/Cons ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] simple parsing (parsec) intro
I wrote a small intro about how to write a parser in haskell. Its basically about parsec and how it works, but its written without directly referencing parsec and aimed towards beginners (basically wrote it for some friends). Any feedback is appreciated. http://www.thenewsh.com/%7Enewsham/formal/parse/parser.lhs Tim Newsham http://www.thenewsh.com/~newsham/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Custom unary operator extension?
Henning Thielemann wrote: The more syntactic constructs exist, the more complicated it becomes to read such programs. Today, if you read a symbolic operator which is not -, not a single dot with a capital identifier to the left (qualification), not a double dot in a bracket (enumeration) and not enclosed in parentheses (prefix mode), then it is an infix operator. Note the already existing exceptions, and I feel these are not complete. With prefix operators it becomes more difficult. Okay, so the choice was to enhance readability. Yes, something can be said for that, because in C++ and C#, operator overloading is a no-go in general, in those language, it is prefered to use clear and long function names. But as Haskell seemed more math-mind oriented, I was just wandering why unary operator support was missing. Since students will surely ask me why I can't create a symbolic operator for the not function, I now have a good answer ready ;-) Thanks, Peter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Installation of GLUT package
On 9/8/07, Ronald Guida [EMAIL PROTECTED] wrote: Clearly, I'm missing something here. Where do I have to go to get the latest version of GLUT? You can get it using darcs: darcs get http://darcs.haskell.org/packages/GLUT/ Also, after I built freeglut with VS-2003, I copied the include files, the lib file, and the dll to the correct places (relative to VS-2003) and I could successfully compile the examples that came with freeglut. MinGW/MSYS doesn't know about VS-2003 include directories, so where am I supposed to put the freeglut include and lib files relative to MinGW/MSYS? Maybe put the include files in /MinGW/include? I'm not sure if you need the lib or dll files for compilation, as it's dynamically linked. But I could be wrong, as MinGW barely works on my Vista. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Where would I find fromInt?
Hi Where would I find the fromInt function, please? Better still, would anyone know how to write a func for converting int to float and vice versa? Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Where would I find fromInt?
Hi Paul -- The function you want is called fromIntegral, and works for all Integral types. Using it, you can add a type signature to specify what you want to change the number to (Float, Double, other Integral type, etc. Example: fromIntegral (4 :: Int) :: Double 4.0 Hope this helps! -- Tom Harper [EMAIL PROTECTED] +1 949 235 0185 Public Key: http://aftereternity.co.uk/rth.asc On 9/9/07, PR Stanley [EMAIL PROTECTED] wrote: Hi Where would I find the fromInt function, please? Better still, would anyone know how to write a func for converting int to float and vice versa? Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Tom Harper [EMAIL PROTECTED] +1 949 235 0185 Public Key: http://aftereternity.co.uk/rth.asc ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Speed of character reading in Haskell
On 7 Sep 2007, at 11:22 pm, Chaddaï Fouché wrote: From what I can see of your program, it would greatly benefit from using Data.ByteString, is there an obvious reason not to use it ? I am writing a a set of tools to process a legacy programming language, as I said. Speed is not, in fact, a central issue. It's just something that came up while I was exploring ways to express it. What *is* a central issue is getting something *right*, *readable*, *rapidly*. Using getContents and walking down a list I get something which is close to Lex in compactness but is much easier to work with; Lex has a nasty habit of either failing to cope entirely or requiring seriously nasty state hacking when you do anything even a little out of the way; Haskell list processing doesn't. Also, I greatly prefer writing to standards. While I turn to GHC for speed (when I can; trying to install GHC 6.6 under Solaris 2.9 was an amazingly painful and ultimately unsuccessful experience), I try to use other Haskell compilers as well, and that means sticking to standard libraries. Data.ByteString is many things, but defined in the Haskell 98 report is not one of them. (Some list operations are too expensive with ByteString but for most string processing it's perfectly fine and much faster than String). I'm sure it's true, but it's quite irrelevant to my question, which is why is using getChar so much slower than using getContents? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Speed of character reading in Haskell
Hi (Some list operations are too expensive with ByteString but for most string processing it's perfectly fine and much faster than String). I'm sure it's true, but it's quite irrelevant to my question, which is why is using getChar so much slower than using getContents? Buffering, blocks and locks. Buffering: getChar demands to get a character now, which pretty much means you can't buffer. Blocks: getContents reads blocks at a time from the underlying library, whereas getChar has to do one character at a time. Locks: getChar has to acquire locks, as does getContents. However, because getContents can operate on blocks, this requires many fewer locks. Thanks Neil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Speed of character reading in Haskell
On Mon, 2007-09-10 at 00:49 +0100, Neil Mitchell wrote: Hi (Some list operations are too expensive with ByteString but for most string processing it's perfectly fine and much faster than String). I'm sure it's true, but it's quite irrelevant to my question, which is why is using getChar so much slower than using getContents? Buffering, blocks and locks. Buffering: getChar demands to get a character now, which pretty much means you can't buffer. Blocks: getContents reads blocks at a time from the underlying library, whereas getChar has to do one character at a time. Locks: getChar has to acquire locks, as does getContents. However, because getContents can operate on blocks, this requires many fewer locks. A little more and that would have Dr. Seuss-esque. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Where would I find fromInt?
To the tune of the theme song of Ghostbusters: You've got an Int But you want Double Who do you call? fromIntegral! (The inverse conversion requires you to think about rounding first.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Elevator pitch for Haskell.
Stefan O'Rear wrote: I'd like to add that, until very recently, Haskell wasn't even *trying* to be ready for prime time. This is a subject that comes up in Ruby-land quite a bit. It piques my curiosity. Obviously, Haskell is not, on its own, sentient. (Nor is the Haskell community a hivemind.) *People* want Haskell to be ready for prime time. Who (besides SPJ) are those people? Why? As for the latter, the reason I hear most often is I want to be able to use the language at my job.* Yet, I have heard two presentations from people who studied the history of Smalltalk/Java/etc. and came to the (informal) conclusion that the very things that enable the language to cross the chasm are the very things that make people like us want to start looking for a new language. A second reason, that Neil mentioned, was I want more libraries. I have no argument with that. :) Any others? * This is somewhat odd, as the strong majority of vocal Rubyists /are/ using it at their job. Perhaps they're preparing for the condition that they lose their job and have to take one up at a Fortune 500 or something. Devin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Comments and/or Criticisms
Hi Any comments and/or criticisms would be most appreciated: --count the occurrences of char in string countC :: Char - [Char] - Int countC x xs = sum [1 | c - xs, c == x] --count occurrences of chars in string countCS :: [Char] - [(Char, Int)] countCS xs = [(x, (countC x xs)) | x - [' '..'z'], (countC x xs) 0] Can anyone come up with a better alternative? Thanks, Paul ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Speed of character reading in Haskell
On 10 Sep 2007, at 11:49 am, Neil Mitchell wrote: Buffering, blocks and locks. Buffering: getChar demands to get a character now, which pretty much means you can't buffer. Eh what? getchar() in C demands to get a character now, which is fully compatible with as much buffering as you want. In fact, looking at the GHC 6.6 sources, I see that getChar - hGetChar which *does* do buffering. Blocks: getContents reads blocks at a time from the underlying library, whereas getChar has to do one character at a time. Again, getchar() in C *returns* one character at a time, but gets oodles of character from the underlying library (read(), as it happens). As noted above, GHC 6.6 *does* read blocks from the underlying library. Locks: getChar has to acquire locks, as does getContents. However, because getContents can operate on blocks, this requires many fewer locks. What's to lock against? I'm writing single-threaded code. As for getContents, each time these lazy read functions are pulled on, they have to check whether the handle has indeed been closed, which is not entirely unlike locking. While getContents / hGetContents is not defined directly in terms of getChar / hGetChar, the implementation *does* do much the same things. (Same blocking and buffering; for locks see previous paragraph.) So it was natural to wonder whether the difference was in *my* code and if so, what I was doing wrong. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Elevator pitch for Haskell.
On Sun, 9 Sep 2007, Devin Mullins wrote: As for the latter, the reason I hear most often is I want to be able to use the language at my job.* Yet, I have heard two presentations from people who studied the history of Smalltalk/Java/etc. and came to the (informal) conclusion that the very things that enable the language to cross the chasm are the very things that make people like us want to start looking for a new language. Any links to these presentations? I'm interested. Thanks. Brian ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Comments and/or Criticisms
On 9/10/07, PR Stanley [EMAIL PROTECTED] wrote: Can anyone come up with a better alternative? *puts on his pointfree hat* import Control.Arrow (()) import Data.List (group, sort) countCS :: [Char] - [(Char, Int)] -- Char can be generalised to any Ord countCS = map (head length) . group . sort Stuart ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Pairing function
I wanted to use the standard name for the function pair :: (a - b) - (a - c) - (a - (b,c)) pair f g x = (f x, g x) but I can find no such function in the Report or its Libraries. Is there a recommended name for this? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Pairing function
On 9/9/07, ok [EMAIL PROTECTED] wrote: I wanted to use the standard name for the function pair :: (a - b) - (a - c) - (a - (b,c)) pair f g x = (f x, g x) but I can find no such function in the Report or its Libraries. Is there a recommended name for this? It is called () and is avaiable from Control.Arrow. -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] zip, map and zipWith for arrays
On 9 Sep 2007, at 10:05 pm, Axel Gerstenberger wrote: I am used to work with map, zip and zipWith, when working with lists, however, I could not find such functions for Arrays. They aren't there for at least two reasons. (1) They are easy to implement on top of the operations that are provided. (EASY is not the same as EFFICIENT, of course.) (2) In some cases it isn't obvious what the operations should be. I note as a counter-argument that Clean provides, in addition to list comprehension and list generators, array comprehension and array generators, so maps and zips of any arity are directly and transparently available in a very Haskell-like language. I note as a counter-counter-argument that Clean is free of Haskell's Ix baggage, which takes us back to (2). zip being a special case of zipWith, let's consider just map and zipWith. amap :: Ix i = (a - b) - Array i a - Array i b amap f arr = listArray (bounds arr) (map f (elems arr)) A more general version of this is available, under that name, in Data.Array.IArray, and Data.Array.MArray gives you mapArray. aZipWith :: Ix i = (a - b - c) - Array i a - Array i b - Array i c aZipWith f a1 a2 = if bounds a1 == bounds a2 then listArray (bounds a1) (zipWith f (elems a1) (elems a2)) else error aZipWith: array bounds do not agree But do you really want aMap's result to have the same bounds as its argument? If not, what bounds do you want it to have? Do you want aZipWith to fail if the arrays haven't exactly the same bounds, or do you want to work with the intersection of their bounds, or what? A worse problem these days is that in the dotted libraries there are so *many* variants of arrays. We need to start writing stuff like aZipWith :: (Ix i, IArray a1 e1, IArray a2 e2, IArray a3 e3) = (e1 - e2 - e3) - a1 i a1 - a2 i e2 - a3 i e3 and this is deeper waters than I am comfortable swimming in. (What's the best thing to read to explain functional dependencies for multi-parameter type classes?) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Installation of GLUT package
Paul L wrote: But again, why stuck with GLUT? Now there is at least one alternative, GLFW (http://glfw.sourceforge.net) a cross-platform framework for OpenGL applications, for which I recently wrote a Haskell interface, downloadable at http://www.haskell.org/soe/software1.htm. It's certainly experimental though. The GLFW C library itself is well documented, but the Haskell module still isn't. The only example so far is the soe.hs in the SOE package. Good news: I abandoned GLUT and looked at GLFW. I had similar problems getting GLFW to work with GHC and GHCi. After a bunch of hacking, I got GLFW to work for me. I have to invoke GHCi with the command line [1] and I have to invoke the compiler like [2], but hey, it works :) [1] ghci myfile.hs glfw_hack.o -lopengl32 -lglu32 [2] ghc --make myfile.hs glfw_hack.o -lopengl32 -lglu32 -- Ron ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Elevator pitch for Haskell.
Brian Hurt wrote: Any links to these presentations? I'm interested. Videos: http://rubyhoedown2007.confreaks.com/session04.html http://rubyhoedown2007.confreaks.com/session07.html Unfortunately, I couldn't find any slides for download. Watch at your own peril! Devin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Comments and/or Criticisms
Alternatives; use your own judgment: PR Stanley wrote: --count the occurrences of char in string countC :: Char - [Char] - Int countC x xs = sum [1 | c - xs, c == x] -- Direct mind-mapping of my brain: countC x = length . filter (c ==) -- Avoids constructing an intermediate list? I dunno. Looks stupid: countC x = foldr (\c s - s + if c == x then 1 else 0) 0 --count occurrences of chars in string countCS :: [Char] - [(Char, Int)] countCS xs = [(x, (countC x xs)) | x - [' '..'z'], (countC x xs) 0] -- What popped into my imperative little brain import Data.Map(assocs, empty, insertWith) countCS str = assocs (countCS' str) where countCS' [] = empty countCS' (x:xs) = insertWith (+) x 1 (countCS' xs) -- but Stuart's pointfree version is so much nicer. Devin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Comments and/or Criticisms
On 9/10/07, PR Stanley [EMAIL PROTECTED] wrote: Hi Any comments and/or criticisms would be most appreciated: --count the occurrences of char in string countC :: Char - [Char] - Int countC x xs = sum [1 | c - xs, c == x] That's a clever implementation, but I think there are clearer ways of achieving the same goal. You could replace sum with length and get the same answer, at which point the list comprehension isn't buying you much. How about this? countC ch xs = length $ filter (ch ==) xs --count occurrences of chars in string countCS :: [Char] - [(Char, Int)] countCS xs = [(x, (countC x xs)) | x - [' '..'z'], (countC x xs) 0] A few things to note: * Those extra parens around countC are unnecessary; function application has highest precedence. * [' '..'z'] has a few issues: it misses a few ASCII characters (including all the control codes), and won't catch non-ASCII characters. * Duplicating the call to countC will probably result in redundant evaluation, so it's best to avoid that if possible -- difficult to avoid cleanly inside a comprehension though. * Scanning the string repeatedly for each potential character [' '..'z'] seems excessive, especially if you want to expand it to include non-ASCII. Better just to deal with the characters actually in the string as they appear, I think. Stuart ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe