[Haskell-cafe] Haskell PNG Writer
Hi list, i am new in Haskell. I need to make images (PNG, JPEG) with haskell, if you can give me a tutorial, thanks! -- Nahuel Rullo ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell PNG Writer
Nahuel Rullo wrote: Hi list, i am new in Haskell. I need to make images (PNG, JPEG) with haskell, if you can give me a tutorial, thanks! Gtk2hs has the ability to read and write PNG and JPEG images. Have a look at the Graphics.UI.Gtk.Gdk.Pixbuf module: http://www.haskell.org/gtk2hs/docs/gtk2hs-docs-0.9.12/Graphics-UI-Gtk-Gdk-Pixbuf.html Specifically, look at pixbufNewFromFile and pixbufSave. If you then take a look at the Graphics.UI.Gtk.Gdk.Drawable module, you'll see a bunch of functions for drawing onto a Pixbuf. (Alternatively you can use Cairo.) However, if you're trying to draw an algorithmically generated set of pixels, you'll probably want to manipulate the underlying bitmap directly. This is Not Fun. Take a look at the QuickDraw demo to see how it's done... HTH. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell PNG Writer
SDL-image (http://hackage.haskell.org/cgi-bin/hackage-scripts/package/SDL-image-0.5.2) also supports this. Luke On Sun, May 4, 2008 at 12:12 AM, Nahuel Rullo [EMAIL PROTECTED] wrote: Hi list, i am new in Haskell. I need to make images (PNG, JPEG) with haskell, if you can give me a tutorial, thanks! -- Nahuel Rullo ___ 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] Haskell PNG Writer
On Sun, May 4, 2008 at 2:12 AM, Nahuel Rullo [EMAIL PROTECTED] wrote: Hi list, i am new in Haskell. I need to make images (PNG, JPEG) with haskell, if you can give me a tutorial, thanks! What kind of images do you need to make? -Brent ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] really difficult for a beginner like me...
2008/5/4 Ivan Amarquaye [EMAIL PROTECTED]: Hi everyone, this is my first posting on here and this was what drove me here and the quest to know more as i anticipate a lot of help and direction in this quite new and different environment haskell.I have this paper that i'm working on and need to solve these scenarios/ cases based on some sample codes: You might receive better help if you asked smaller, more specific questions. This looks like homework, and even if it's not, we are a homework-friendly crowd, meaning: nobody is going to write code for you. We will answer questions in words, point you to useful library functions, give you feedback on approaches you outline to us, etc. So break up the problem. Try no. 1 by yourself, and if you can't do it, then describe what you tried and how it didn't work. Giving an outline of how you think you should approach the problem from a purely functional perspective will help, so we can help you modify and correct that idea. The more thought you put in by yourself before asking us, the more you will get out of our responses. But be much more specific. I cannot answer a question this large. Luke ___ 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?
On 4 May 2008, at 17:33, PR Stanley wrote: 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. Bob ___ 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
Re: [Haskell-cafe] unapplying function definitions?
On Sun, May 4, 2008 at 12:48 PM, PR Stanley [EMAIL PROTECTED] wrote: 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? Essentially, a normal form is an expression where there are no more function applications that can be evaluated. For example, the expression '5' is a normal form; 'succ 5' is not a normal form since the succ can be applied to the 5, producing the normal form 6. To give another example of what Hutton means, suppose we are given the function definition head (x:xs) = x Then if we have the expression 'head (1:2:[])', noting that this matches the left-hand side of the definition of head, we can apply that definition to produce the equivalent expression '1'. Given the expression '2', on the other hand, and noting that this matches the *right*-hand side of the definition of head, we can *unapply* the definition to produce the equivalent expression 'head (2:[4,5,6])' (for example). Applying a function definition (moving from the left side of the definition to the right side) brings us closer to a normal form, since there's one less function application. Unapplying a function definition (moving from the right side to the left side) moves us further away from normal form since we have introduced another function application. Of course, you would never want an evaluator to unapply functions in this way, but when reasoning about programs as humans, it can sometimes be useful in proving things. Does that help clear things up? -Brent ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] really difficult for a beginner like me...
2008/5/4 Ivan Amarquaye [EMAIL PROTECTED]: thanks for the tip thereits been four gruesome days and i just don't seem to make any understanding of how to implement some changes or create some new functions due to the fact that im so new to Haskell and functional programming. For the very first case of allowing hyphenated words to be treated as single words i manged to successfully do that by adding to the definition of the splitWords function to also accept characters such as - and it worked perfectly after running it. The next case posed a headache for me as i have been on it for 3 days now. From my understanding, it means in situations where your writing a sentence and you get to the end of the line while writing a word, you decide to put a hyphen there and continue on the other line. So the case demands that i allow sentences that end with hyphens and continue on the next line to drop the hyphen and be a single word on that same line without having to continue on the next line so this was how i foresee the input it in hugs: Input: makeIndex these are the very same stuff they tell each-\nother output: should be this: [[1]these],[[1]eachother]. 1 indicates they are on the same line and the others are left out as the index takes words greater than 4 characters and i have been struggling with this since. i tried on several counts to include in the splitwords function to dropWhile - is found in the words but it turned out an error.I also tried creating a new function to do that didnt succeed either can anybody help me out in this regard. There are many ways of doing this of course. Perhaps you need to write a function like so: -- fixes up hyphenated words fixupHyphens :: [ (Int, Word) ] - [ (Int, Word ) ] fixupHyphens ( (line1, word1):(line2:word2):xs ) | ... check if word1 ends with hyphen and line2 /= line1 ... = ( line1, ... something .. ) : fixupHyphens xs | otherwise = (line1, word1):(line2:word2): fixupHyphens xs fixupHyphens xs = xs Then you can insert this function in the appropriate place in the makeIndex function (probably before sorting, as you depend on the words showing up in order). -- Sebastian Sylvan +44(0)7857-300802 UIN: 44640862 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Control.Exception.evaluate - 'correct definition' not so correct
Hello, On Sat, May 3, 2008 at 3:56 AM, apfelmus [EMAIL PROTECTED] wrote: Bryan Donlan wrote: evaluate x = (return $! x) = return However, if = is strict on its first argument, then this definition is no better than (return $! x). According to the monad law f = return = f every (=) ought to be strict in its first argument, so it indeed seems that the implementation given in the documentation is wrong. From the monad law we can conclude only that (= return) is strict, not (=) in general. For example, (=) for the reader monad is not strict in its first argument: m = f = \r - f (m r) r So, (undefined return 2) = (return 2) -Iavor ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] sound synthesis
On May 2, 2008, at 2:58 AM, Thomas Girod wrote: I remember an article ranting about how lazy evaluation would be great to do signal processing, but it was lacking real world example. I did something similar a few weeks ago. I used libmad to lazily decode an MP3 file and play it using OS/X's core audio. Here's that post, with links to the libmad bindings (which might be useful for you, even if the CoreAudio isn't.) chris http://www.haskell.org/pipermail/haskell-cafe/2008-March/040796.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Parsec on TeX
I am new to Haskell and Parsec, and am trying to understand both. I tried to follow the example of how to use Parsec to parse TeX begin/end groups, but can't get it to run. I'm using HUGS -98 on Debian. When I copied the code I got errors about unknown terms (reserved and braces). I've tried to get them from the lexer, but now get this error :load grammar.hsl ERROR grammar.hsl:21 - Type error in explicitly typed binding *** Term : envEnd *** Type : String - GenParser Char a [Char] *** Does not match : String - Parser () Can anyone help me understand what the problem is? Here's the code the caused the above error; I believe the part after --TeX example is verbatim from the Parsec documentation. I picked haskell as the language for to lexer arbitrarily. import Text.ParserCombinators.Parsec import qualified Text.ParserCombinators.Parsec.Token as P import Text.ParserCombinators.Parsec.Language(haskell) reserved = P.reserved haskell braces = P.braces haskell -- TeX example environment = do{ name - envBegin ; environment ; envEnd name } | return () envBegin :: Parser String envBegin = do{ reserved \\begin ; braces (many1 letter) } envEnd :: String - Parser () envEnd name = do{ reserved \\end ; braces (string name) } ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parsec on TeX
On 2008 May 4, at 23:40, Ross Boylan wrote: ERROR grammar.hsl:21 - Type error in explicitly typed binding *** Term : envEnd *** Type : String - GenParser Char a [Char] *** Does not match : String - Parser () Hugs is prone to error messages that obscure the problem. The trick here is to realize that the type Parser () is the same as GenParser Char a (); this then tells you that you have used a function that returns a [Char] (aka String) where a type () (Haskell's version of (void)) is expected. envEnd :: String - Parser () envEnd name = do{ reserved \\end ; braces (string name) } Line 21 is ; braces (string name); it is producing a String, when you need a (). One fix is to add one more line: envEnd :: String - Parser () envEnd name = do reserved \\end braces (string name) return () Another possible fix is to change the type of envEnd to String - Parser String; this may depend on how it's used. -- 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] Parsec on TeX
On Sun, 2008-05-04 at 20:40 -0700, Ross Boylan wrote: I am new to Haskell and Parsec, and am trying to understand both. I tried to follow the example of how to use Parsec to parse TeX begin/end groups, but can't get it to run. I'm using HUGS -98 on Debian. When I copied the code I got errors about unknown terms (reserved and braces). I've tried to get them from the lexer, but now get this error :load grammar.hsl ERROR grammar.hsl:21 - Type error in explicitly typed binding *** Term : envEnd *** Type : String - GenParser Char a [Char] *** Does not match : String - Parser () Can anyone help me understand what the problem is? Here's the code the caused the above error; I believe the part after --TeX example is verbatim from the Parsec documentation. I picked haskell as the language for to lexer arbitrarily. import Text.ParserCombinators.Parsec import qualified Text.ParserCombinators.Parsec.Token as P import Text.ParserCombinators.Parsec.Language(haskell) reserved = P.reserved haskell braces = P.braces haskell -- TeX example environment = do{ name - envBegin ; environment ; envEnd name } | return () envBegin :: Parser String envBegin = do{ reserved \\begin ; braces (many1 letter) } envEnd :: String - Parser () envEnd name = do{ reserved \\end ; braces (string name) } braces returns, in this case, a string, so the type of envEnd is String - Parser String. You can either change the type and add a return () to environment after envEnd or add a return () to envEnd. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parsec on TeX
On Sun, 2008-05-04 at 23:58 -0400, Brandon S. Allbery KF8NH wrote: On 2008 May 4, at 23:40, Ross Boylan wrote: ERROR grammar.hsl:21 - Type error in explicitly typed binding *** Term : envEnd *** Type : String - GenParser Char a [Char] *** Does not match : String - Parser () Hugs is prone to error messages that obscure the problem. The trick here is to realize that the type Parser () is the same as GenParser Char a (); this then tells you that you have used a function that returns a [Char] (aka String) where a type () (Haskell's version of (void)) is expected. envEnd :: String - Parser () envEnd name = do{ reserved \\end ; braces (string name) } Line 21 is ; braces (string name); it is producing a String, when you need a (). One fix is to add one more line: envEnd :: String - Parser () envEnd name = do reserved \\end braces (string name) return () Another possible fix is to change the type of envEnd to String - Parser String; this may depend on how it's used. First, I'm really impressed with the fast and helpful responses from several people! So the example is wrong? What inference should I draw about the state of Parsec and its documentation? I was thinking of trying Frost et al's X-SAIGA, but that the better documentation for parsec would be a plus. I had thought HUGS made more sense for fiddling around, but it seems all I'm doing is loading files anyway. What is the style people use for this exploratory work? I've already installed haskell-mode for emacs and ghc6, but it's not clear to me to what extent the former servers as a development environment rather than just a language formatter. Thanks. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parsec on TeX
On 2008 May 5, at 0:14, Ross Boylan wrote: So the example is wrong? What inference should I draw about the state of Parsec and its documentation? I was thinking of trying Frost et al's X-SAIGA, but that the better documentation for parsec would be a plus. The original documentation which you will probably find via Google is several years out of date; unfortunately, nobody has updated it and the newer API documentation lacks most of the actual details of how to *use* Parsec --- so really you need to have daan's Parsec paper and the Haskell library API documentation ( http://www.haskell.org/ghc/docs/latest/html/libraries/parsec/Text-ParserCombinators-Parsec.html ) open at the same time to see how things have changed. I will note that a newer version of Parsec is in development; I am hoping it will have somewhat better documentation (preferably an updated version of the original Parsec paper). I had thought HUGS made more sense for fiddling around, but it seems all I'm doing is loading files anyway. What is the style people use for this exploratory work? I've already installed haskell-mode for emacs and ghc6, but it's not clear to me to what extent the former servers as a development environment rather than just a language formatter. ghci (the interpreter component of GHC) works much like hugs but is much more up to date; there are a number of useful libraries which either haven't been ported to or simply don't work with Hugs. (The new Parsec is one of these, as it works with the ByteString library (much faster than standard Strings, which are naive linked lists of characters); ByteString really needs to be compiled and Hugs is only an interpreter.) -- 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] Parsec on TeX
I will add one more comment: perhaps the biggest thing Haskell has going for it has nothing to do with the language itself; as you noticed, it's the community. One might expect to find crusty mathematicians and dubiously social geeks(*), but in fact the Haskell community is one of the friendliest and most helpful I've encountered anywhere. (*) ironically, the person saying this is both dubiously social and an even crustier system administrator :) -- 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] Parsec on TeX
On Sun, 2008-05-04 at 21:33 -0700, Ross Boylan wrote: On Sun, 2008-05-04 at 23:58 -0400, Brandon S. Allbery KF8NH wrote: On 2008 May 4, at 23:40, Ross Boylan wrote: ERROR grammar.hsl:21 - Type error in explicitly typed binding *** Term : envEnd *** Type : String - GenParser Char a [Char] *** Does not match : String - Parser () Hugs is prone to error messages that obscure the problem. The trick here is to realize that the type Parser () is the same as GenParser Char a (); this then tells you that you have used a function that returns a [Char] (aka String) where a type () (Haskell's version of (void)) is expected. envEnd :: String - Parser () envEnd name = do{ reserved \\end ; braces (string name) } Line 21 is ; braces (string name); it is producing a String, when you need a (). One fix is to add one more line: envEnd :: String - Parser () envEnd name = do reserved \\end braces (string name) return () Another possible fix is to change the type of envEnd to String - Parser String; this may depend on how it's used. First, I'm really impressed with the fast and helpful responses from several people! So the example is wrong? What inference should I draw about the state of Parsec and its documentation? I was thinking of trying Frost et al's X-SAIGA, but that the better documentation for parsec would be a plus. Parsec is currently maintained, but wasn't maintained for quite a while (admittedly, it didn't really require much maintenance; it was certainly rampantly used during that time.) Daan's paper on Parsec that you are reading/read is probably the best tutorial-like introduction. The reference documentation has been Haddock-ed for the newer version of Parsec (which you are almost certainly not using, but it is still very similar.) http://hackage.haskell.org/packages/archive/parsec/3.0.0/doc/html/Text-Parsec.html Unfortunately, Daan seems to have disappeared off of the face of the internet so there isn't anything that can be done about fixing that documentation (and likely that is in large part why this error is still there.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe