Re: [Haskell-cafe] IO help
Have a look at the wikibook: http://en.wikibooks.org/wiki/Haskell/Simple_input_and_output Am 07.05.2009 um 11:46 schrieb applebiz89: I havent done much IO at all in haskell, only within the function itself. However I want to get the input from the interface for the function and havent done this before. In my main function, I want to ask the user what they would like to do 'become fan' for example, then with their choice initiate the function and ask for the appropriate input for that function. This is the code below: main :: IO() do putStr Hi there! what is your name: fanName = getLine do putStr 1 = Insert film, 2 = Become a Fan, 3 = The number of fans of a film, 4 = Film released in a year: input = getLine read input :: Int (if input == 1 then main x = insertFilm [] else if input == 2 then main x = becomeFan [] else if input == 3 then main x = numberOfFans []) Say they choose film in a given year function function: filmsInGivenYear :: Int - [Film] - [String] filmsInGivenYear filmYear films = [ title | (Film title director year fans) - films, year == filmYear] I need to ask the user what filmYear they want to insert. But i need to do this from the main function...I chose to do an if statement to choose what function they want, but i dont know where to go from there? any help will be greatly appreciated. thanks apple -- View this message in context: http://www.nabble.com/IO-help- tp23423403p23423403.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Unfold fusion
Hello, I'm trying to prove the unfold fusion law, as given in the chapter Origami Programming in The Fun of Programming. unfold is defined like this: unfold p f g b = if p b then [] else (f b):unfold p f g (g b) And the law states: unfold p f g . h = unfold p' f' g' with p' = p.h f' = f.h h.g' = g.h Foremost I don't really see why one would want to fuse h into the unfold. h is executed once, at the beginning and is never needed again. Can someone give me an example? So, this is what I got so far: unfold p f g.h = (\b - if p b then [] else (f b): unfold p f g (g b).h = if p (h b) then [] else (f (h b)) : unfold p f g (g (h b)) = if p' b then [] else f' b: unfold p f g (h (g' b)) not very much. I kinda see why it works after I unfold some more, but I can't really prove it. I suspect I need some technique I haven't learned yet. I've heard about fixpoint induction, that looks promising, but Google knows very little about it. I hope somebody can give me some hints. Regards, Adrian PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Looking for the fastest Haskell primes algorithm
I've just uploaded a package with some functions I had lying around. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/Numbers Am 14.04.2009 um 14:40 schrieb Niemeijer, R.A.: Today I happened to need a large list of prime numbers. Obviously this is a well-known problem, so I figured there would be something on Hackage that I could use. Surprisingly, there isn’t, or if there is it’s not easy to find. Searching for prime or primes on Hackage reveals nothing. Searching for primes on Hayoo gives Codec.Encryption.RSA.NumberTheory, but that uses the inefficient one-liner implementation. The HaskellWiki article on primes (http:// www.haskell.org/haskellwiki/Prime_numbers) has a number of implementations, but the faster they get, the longer and uglier they become. Since it’s such a common problem I’d say it would be a good idea to add a package to Hackage that exports primes :: [Integer] and hides the ugly implementation details. Data.Numbers.Primes seems a logical choice for the namespace, but I’m open to suggestions. The trick then is to find the most efficient implementation of primes. The Haskell wiki article mentions ONeillPrimes.hs as one of the fastest ones, but maybe there’s a faster version. So my question is: does anybody know what the fastest Haskell algorithm for generating primes is? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: [Haskell-beginners] appropriateness of haskell for GUIs
Am 21.03.2009 um 13:30 schrieb Michael Mossey: Thomas Davie wrote: On 21 Mar 2009, at 00:16, Michael P Mossey wrote: Hello, I'm totally new to Haskell. I'm thinking of using it for a personal project, which is a gui-based musical score editor. The rough situation of GUI programming on Haskell is that it works just as well as in any imperative programming language. This is rather disappointing, simply because so many other things are massively easier in Haskell, and this isn't true of GUI programming (yet). Hi Bob, I can imagine that GUI programming is no easier (yet). It is inherently very stateful. GUI's have modes, such as which screens are displayed, which dialogs are displayed, which options within those dialogs are valid given the other state of the program, etc. When I write GUIs, I often diagram them as state machines to get a handle on what's going on. So, I'm not familiar with GUI programming on Haskell, but would you say the statefulness of GUIs (in their typical implementations) is the reason they are no easier on Haskell? I strongly prefer to use qtHaskell because I'm familiar with Qt, and Qt is extremely capable. For example, it can draw text and shapes with antialiasing, which will be great for a music score editor. Music scores have lots of small shapes to fit on the screen, and antialiasing will provide ease of reading. I don't know how much of Qt is implemented in qtHaskell, or whether the latest version of Qt (4.4) is implemented. Thanks, Mike The main problem is, as far as I know, the complete lack of any usable GUI designer. You have to type everything yourself. That's very annoying. It's a lot easier in other languages because your tools take away the cumbersome twiddling with widgets. However, I haven't googled. Maybe the situation has changed since I last looked. Regards, Adrian PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: [Haskell-beginners] laziness and optimization
You should not rely on the compiler to spot such things. As far as I know GHC doesn't do automatic caching (in many cases that would hurt performance, I think). Have a look at http://haskell.org/haskellwiki/ Memoization perhaps. Am 21.03.2009 um 14:02 schrieb Michael Mossey: I understand a bit about the concept of lazy evaluation. I think of that as saying an imperative language would always make one evaluation, whereas Haskell might make 0 evaluations. I have another similar situation where an imperative language would make N evaluations of the same expression, and I would like Haskell to make only 1. This is the situation: the graphical score editor displays LayoutItems. A LayoutItem can be a single displayed entity, like a round notehead, or it can be composed of several entities. A common situation in my code is the need to determine the size and shape of a LayoutItem. For a fundamental item, this can be looked up in a table or read from the font properties. For a composite item, some computation is required: the code must determine the positions of each sub-item and compute the bounds of a shape containing all of them. It's this latter computation, finding the bounds of a composite item, which might come up multiple times. Consider that I ask for the bounds of a composite-composite item (a composite item composed of composite items). It will run the computation associated with each composite sub-item, even though it is very likely I already make that computation when I first constructed and placed that sub- item. In an imperative language, one might cache values for later lookup. This raises the problem of keeping the cache current to the current state. So I'm wondering to what extent the haskell compiler recognizes computations it's done before. In a purely functional language this should be pretty easy, right? If it sees the same expression, it knows it will have the same value. That's my understanding, so far. Thanks, Mike ___ Beginners mailing list beginn...@haskell.org http://www.haskell.org/mailman/listinfo/beginners PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Fw: hw do i solve this problems:
http://lmgtfy.com/?q=haskell+run+length+codingl=1 But you'll learn nothing if you just copy that Am 19.03.2009 um 03:24 schrieb THANDO NTUANE: - Forwarded Message From: THANDO NTUANE thandodar...@yahoo.com To: Haskell-Cafe@haskell.org Sent: Thursday, March 19, 2009 10:22:40 AM Subject: hw do i solve this problems: kindly help me.. im stack but managed to solve exercise 1 and 2. task1.docx ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Query on list comprehension
Use a nested list comprehension, for example Prelude [['a'| i - [0..n]]++\n|n - [1..3]] [aa\n,aaa\n,\n] Am 18.03.2009 um 07:47 schrieb Melanie_Green: What are the limitations of list comprehension. I want to use listcomprehension to output the pattern below. So a mixture of a's and newline characters. The part im stuck at is creating arguments in the listcomprehension to stop at some point then execute next loop. Is it even possible to create the pattern below purely from list comprehension.Thankyou in advance. a aa aaa -- View this message in context: http://www.nabble.com/Query-on-list- comprehension-tp22573574p22573574.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: [Haskell-beginners] folds -- help!
That's why I said for appropriate g and f. But I see that my wording was misleading. However you can say: foldl' oplus alpha bs =(foldr f id bs) alpha where f a g = \alpha - g (alpha `oplus` a) foldr' oplus alpha bs = (foldl f id bs) alpha where f g a = \alpha - g (a `oplus` alpha) And it works as long as oplus is strict in both arguments. Am 10.03.2009 um 21:54 schrieb John Dorsey: Adrian Neumann wrote: Notice that there is no difference between foldr g a foldl f a (for appropriate g and f) if g and f are strict in both arguments. Be careful... as apfelmus noted elsewhere in this thread, that's not (in general) true. Prelude foldr (^) 2 [3,5] 847288609443 Prelude foldl (^) 2 [3,5] 32768 The reason? Integer exponentiation (^) isn't associative and commutative. So the first is (3 ^ (5^2)) = 3^25, while the second is ((2 ^ 3) ^ 5) = 2^15. Cheers, John ___ Beginners mailing list beginn...@haskell.org http://www.haskell.org/mailman/listinfo/beginners PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to catch error in array index when debugging
You can use the ghci debugger http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci- debugger.html it can set breakpoints on exceptions. Am 14.03.2009 um 09:39 schrieb Colin Paul Adams: I'm getting a runtime failure Error in array index. This causes ghci to exit. Is there a way to get it to break instead, so I can find out which function is failing? -- Colin Adams Preston Lancashire ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A systematic method for deriving a defintion of foldl using foldr?
Read this excellent paper: http://www.cs.nott.ac.uk/~gmh/fold.pdf Am 11.03.2009 um 19:24 schrieb R J: foldl and foldr are defined as follows: foldr:: (a - b - b) - b - [a] - b foldr f e [] = e foldr f e (x : xs) = f x (foldr f e xs) foldl:: (b - a - b) - b - [a] - b foldl f e [] = e foldl f e (x : xs) = foldl f (f e x) xs 1. I understand how these definitions work, and yet I'm unable to implement foldl in terms of foldr. What's a systematic approach to identifying such an implementation, and what is the implementation? 2. I believe that the reverse implementation--namely, implementing foldr in terms of foldl--is impossible. What's the proof of that? 3. Any advice on how, aside from tons of practice, to develop the intuition for rapidly seeing solutions to questions like these would be much appreciated. The difficulty a newbie faces in answering seemingly simple questions like these is quite discouraging. Express your personality in color! Preview and select themes for Hotmail®. See how. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Basic problem in Haskell language design?
You could turn on -Wall to get a whole bunch of such warnings. Am 01.03.2009 um 14:26 schrieb Nicu Ionita: Hi, Today I found the following problem when writing a simple function: -- Whole info from a word8 list to moves movesFromWord8s :: [Word8] - [Move] movesFromWord8s (f:t:ws) = (f, t) : movesFromWord8s ws moverFromWord8s _ = [] Here I made a small typo in the second equation, writing mover... instead of moves... for the name of the declared function. Of course this is an error, because I have non-exhaustive patterns in the function movesFromWord8s. But the compiler (here GHC 6.8.2 on WinXP) has in principle no chance to detect this mistake, I saw it only in QuickCheck (aka at run-time). I think this is a basic problem with the language design. In small programs it's not so bad, but in large ones this could be. What do you think about it? Are there possible solutions or workarounds? Nicu Ionita ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] (Off-topic) CUDA
Am 05.02.2009 um 09:10 schrieb Andrew Coppin: And so, inspired by the marketing litrature, I just spent £££ on a very expensive new GPU that supports CUDA. The only problem is... I can't seem to get any software to use it. Does anybody know how to make this stuff actually work? (Also... Haskell on the GPU. It's been talked about for years, but will it ever actually happen?) Have a look at Obsidian http://www.cse.chalmers.se/~joels/ and ask Mr Svenson if there is anything working. PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANNOUNCE: DecisionTree 0.0
Hello, it is my pleasure to announce the DecisionTree package. It provides an implementation of the ID3 algorithm [1] and can be used to classify data with discrete valued attributes. You can get it from * hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ DecisionTree * my own webspace: http://page.mi.fu-berlin.de/aneumann/decisiontree/ DecisionTree-0.0.tar.gz At this stage it is very likely buggy and slow, as I don't have a sufficiently large dataset to test with. You are encouraged to have a look at the source, it is quite short and well commented. Please feel free to make suggestions, send in patches or point me to some dataset I could use for testing. Regards, Adrian PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Elevator pitch for functional programming
There was a thread about that: http://www.haskell.org/pipermail/haskell-cafe/2007-September/ 031402.html Am 20.01.2009 um 11:07 schrieb Jim Burton: Hi, I will be a TA on a comparative PL course and I'm looking for small examples (ammunition) which motivate the use of Haskell and functional programming generally. The course is for 1st year Software Engineers, none of whom are likely to have used a functional language. They will all have experience programming Java and a little C++, with a few of them knowing Python, Ruby, PHP etc etc too. If anyone has code snippets which are the equivalent of an elevator pitch for FP, I would be very grateful to see them. What I want are some small concrete examples of idioms which are natural and powerful in Haskell but difficult or impossible in, say, Java. So I can produce examples of some of the things that make FP powerful, elegant, expressive etc: higher order functions, polymorphism, composition (ask them to write (.) in Java :-)), partial application and so on. I will point any interested souls to Hughes' great paper [1]. But I have little time and it might be hard to put across why they would want to do these things in the first place. I was looking for something that speaks directly to the kind of problems they face in languages like Java... Types are a good example because Java programmers generally already appreciate the help they get from compiler messages etc, so you can sell a more flexible, enhanced form of this. Purity might appeal to anyone who has longed to be able to reason about nastily complex code with a lot of shared state. Laziness, streams? Hard to do in Java (I presume) but also quite hard to sell the need. The existence of an O'Reilly book will help, especially one that can be sampled online, so I'll point them at RWH for extended concrete examples. They will need to be already sold before they will bother with that though. Thanks, Jim [1] http://www.cs.chalmers.se/~rjmh/Papers/whyfp.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] definition of data
You need some type constructor: data Tree a = Leaf a | Branch (Tree a) (Tree a) Am 01.01.2009 um 08:32 schrieb Max.cs: hi all, I want to define a data type Tree a that can either be a or Branch (Tree a) (Tree a)? I tried data Tree a = a | Branch (Tree a) (Tree a) deriving Show but it seems not accpetable in haskell ? any way I could achieve this ? Thanks max ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] instance Enum [Char] where ...
Better would be [] = 0 ['a'] = 1 ['b'] = 2 ... ['z'] = 26 ['a','a'] = 27 ['a','b'] = 28 (asuming Char = ['a'..'z']) Am 30.12.2008 um 04:25 schrieb JustinGoguen: I am having difficulty making [Char] an instance of Enum. fromEnum is easy enough: map fromEnum to each char in the string and take the sum. However, toEnum has no way of knowing what the original string was. For example, running fromEnum on the string d will result in 100. But when we pass 100 to toEnum, it does not know if it should treat 100 as d or 22 (fromEnum '2' == 50). Source so far: instance Enum [Char] where succ = undefined pred = undefined toEnum n = undefined -- what to do? fromEnum xs = sum $ map fromEnum xs ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Data.List.sort, not so good?
Hello Haskell-Cafe, lately I've been playing around with sorting. I discovered that Data.List.sort is not as optimized I thought. At least not for random lists. I think we should consider adding a Data.List.Sort package to hackage (Similar to Data.List.Split) that offers a wide variety of sorting algorithms. I don't consider myself to be a very advanced Haskell programmer, but I could come up with a Mergesort that beats List.sort, time- and spacewise. http://hpaste.org/13403 On my machine List.sort takes ~10 sec, mergeSort 7, qs 4 (compiled with -O2). List.sort eats too much ram to sort 20.000.000 ints, my algorithms don't. QuickCheck says my implementations are correct. I suppose List.sort does clever things for nonrandom lists, that I didn't consider? I had a look at the source, but I couldn't find anything obvious. Adrian PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.List.sort, not so good?
Ah that's interesting. Now my Mergesort is exactly as fast as List.sort. I thought GHC was smart enough to do that kind of inter- module optimisation. Still, Quicksort is twice as fast, so at least one argument for a Data.List.Sort package on hackage remains. Am 29.12.2008 um 16:43 schrieb Bayley, Alistair: From: haskell-cafe-boun...@haskell.org [mailto:haskell-cafe-boun...@haskell.org] On Behalf Of Adrian Neumann I don't consider myself to be a very advanced Haskell programmer, but I could come up with a Mergesort that beats List.sort, time- and spacewise. http://hpaste.org/13403 On my machine List.sort takes ~10 sec, mergeSort 7, qs 4 (compiled with -O2). List.sort eats too much ram to sort 20.000.000 ints, my algorithms don't. QuickCheck says my implementations are correct. Your single module might be benefiting from optimisation; specifically, specialisation to Ints, which would allow the dictionary lookup to be removed. Can you get the same performance if you move your mergeSort qs functions into a separate module, and only export mergeSort qs? Alistair * Confidentiality Note: The information contained in this message, and any attachments, may contain confidential and/or privileged material. It is intended solely for the person(s) or entity to which it is addressed. Any review, retransmission, dissemination, or taking of any action in reliance upon this information by persons or entities other than the intended recipient(s) is prohibited. If you received this in error, please contact the sender and delete the material from any computer. * PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What are side effects in Haskell?
Am 23.12.2008 um 15:16 schrieb Hans van Thiel: Hello All, I just saw somewhere that one of the purposes of monads is to capture side effects. I understand what a side effect is in C, for example. Say you want to switch the contents of two variables. Then you need a third temporary variable to store an intermediate result. If this is global, then it will be changed by the operation. But the two variables have also changed. After all they have different values after the switch. You see, even locally changing a variable is a side-effect. It changes the state of the program. Pure Haskell programs on the other hand have no notion of state, there are no variables which can change their value. Every time you want to manipulate something you're actually generating an new copy. You mustn't think of a haskell program as a series of changes to some state. However when you *do* want state you can simulate it with a monad. The IO Monad is a special case here, since its actions don't change your program, they change the world the program is running in (writing files etc.). getLine etc are functions when you think of them as taking a hidden parameter, the state of the world. So getChar would become getChar :: World - (Char,World) but the world stays hidden inside the IO Monad. Regards, Adrian PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Trouble with interact in ghci
Hi, I have a strange problem with interact on OS X (ghc 6.10.1). It seems to garble stdin. I have some code here http://hpaste.org/13135#a2 , for testing purpose: *Main main 1 1.0 2 1.5 3 2.0 *Main setNonBlockingFD: invalid argument (Bad file descriptor) 11:40:45 ~/Desktop (I hit ctrl-D) *Main main 1 1.0 2 1.5 3 2.0 ^CInterrupted. *Main main *** Exception: stdin: hGetContents: illegal operation (handle is closed) *Main Someone on #haskell suspected my editline to be the culprit. Does anyone of you know what I can do about this problem? Greetings, Adrian PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Compilers
Am 27.11.2008 um 09:23 schrieb Don Stewart: allbery: On 2008 Nov 26, at 16:58, Matthias Kilian wrote: On Wed, Nov 26, 2008 at 09:35:01PM +, Andrew Coppin wrote: It is a fork of the JHC compiler, which should be easier to look up. There is also Hugs, as you mentioned. In addition, you may want to look at YHC and NHC. Yeah, the implementations page on the Wiki basically says that there's GHC and Hugs, and there's also these things called YHC, NHC and JHC. All the documentation I've read makes these latter compilers sound highly experimental and unusable. I would't call nhc experimental; it's quite usable, at least for standard Haskell-98 stuff (plus some language extensions). On a related topic: whatever happened to the compiler shootout? (Aside from dons leaving unsw) Malcolm continues the tradition, http://code.haskell.org/nobench/ All result links are broken. PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Counting beta reductions for a Haskell program...
Hugs has, afaik, a output reduction count option somewhere. At least it had one the last time I used it. - Adrian Am 22.11.2008 um 06:22 schrieb kk08: Thanks. I heard that a Gofer compiler (a Haskell dialect) supports counting the Beta reductions. Hence I thought GHC/Hugs would have a similar facility. Ryan Ingram wrote: This doesn't make a whole lot of sense. One of the reasons GHC-compiled code is so fast is that it turns into straight-line code whenever possible, via inlining, primitive optimizations, etc. - ryan [1] http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.53.3729 On Fri, Nov 21, 2008 at 8:46 PM, kk08 [EMAIL PROTECTED] wrote: Does GHC supports/has a command for counting total beta reductions taken by a program? Thanks. -- View this message in context: http://www.nabble.com/Counting-beta-reductions-for-a-Haskell- program...-tp20623025p20623025.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ 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 -- View this message in context: http://www.nabble.com/Counting-beta- reductions-for-a-Haskell-program...-tp20623025p20633639.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [ANN] Haskell Cheatsheet v1.0
Thank you for your work! I just glanced over it but I'll suggest it to be linked to from the homepage of my university's functional programming course. However, thirteen pages can hardly be called cheatsheet. It's more like a quick reference. You could add [100,99..] infinite liste of numbers from 100 downwards to you numbers section, as it is an example where the range does go backward. Adrian Am 11.10.2008 um 01:08 schrieb Justin Bailey: All, I've created a cheat sheet for Haskell. It's a PDF that tries to summarize Haskell 98's syntax, keywords and other language elements. It's currently available on hackage[1]. Once downloaded, unpack the archive and you'll see the PDF. A literate source file is also included. If you install with cabal install cheatsheet, run cheatsheet afterwards and the program will tell you where the PDF is located. The audience for this document is beginning to intermediate Haskell programmers. I found it difficult to look up some of the less-used syntax and other language stumbling blocks as I learned Haskell over the last few years, so I hope this document can help others in the future. This is a beta release (which is why I've limited the audience by using hackage) to get feedback before distributing the PDF to a wider audience. With that in mind, I welcome your comments or patches[2]. Justin [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ CheatSheet [2] git://github.com/m4dc4p/cheatsheet.git ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Health effects
The Wikipedia says: For a finite set of points in the plane, each colored red or blue, there is a line that simultaneously bisects the red points and bisects the blue points, that is, the number of red points on either side of the line is equal and the number of blue points on either side of the line is equal. Does this work with more than two colours? i.e. can I recursively subdivide the halves into quarters with another cut? Am 01.10.2008 um 15:33 schrieb Dominic Steinitz: Adrian Neumann aneumann at inf.fu-berlin.de writes: I often wonder how many cuts you need to divide a steak in n pieces. You can obviously get n pieces with (sqrt n) cuts by cutting a grid. But I'm sure some smart mathematician thought of a (log n) way. You might try the ham sandwich theorem http://en.wikipedia.org/wiki/Ham_sandwich_theorem as an hors d'oeuvre. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Health effects
I often wonder how many cuts you need to divide a steak in n pieces. You can obviously get n pieces with (sqrt n) cuts by cutting a grid. But I'm sure some smart mathematician thought of a (log n) way. Adrian Am 29.09.2008 um 21:43 schrieb Andrew Coppin: The other day, I sat down to eat a 2 Kg block of chocolate - one of those ones that's divided into lots of little squares. I proceeded to recursively subdivide it into smaller and smaller blocks, and then eat the individual squares in depth-first order. It was only after getting through 16 of the things that I stopped to notice that the whole bar just happens to have an exact power of two squares on it. And it was some time after *that* when I thought to myself ...woah, maybe do too much Haskell? o_O Seriously, who recursively subdivides their food? I think I have something wrong with me... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Looking for a more functional way to do this
There is the State Monad which is build just for that kind of purpose, I believe: http://www.haskell.org/all_about_monads/html/statemonad.html That would safe you from passing around the State Jefferson Heard schrieb: Working with HOpenGL and GLUT, I find myself approaching a common problem with a common solution that I don't really like all that much, as it reeks of procedural programming. Basically the problem is that of complex program state, such that when the user provides input to the program in the form of a mouse click or a typed string or character, the program updates its internal state to reflect this, whether that's changing the rotation, scale, or position of a screen element, or deciding what data to have loaded from disc. What I often do is something that looks like this: data ProgramState = ProgramState { some_associative_data :: Map String String , position :: GL.Vector3 Float , look_at :: GL Vector3 Float , selectables :: Map GLuint NamedObject } render :: IORef ProgramState - IO () render state = do st - readIORef state ... handleMouseClicks :: IORef ProgramState - GLUT.KeyboardMouseHandler handleMouseClicks state ... = do st - readIORef state ... main = do ... let st = ProgramState { Map.empty ... } render' = render st mouse' = handleMouseClicks st GLUT.renderCallback $= render GLUT.keyboardMouseCallback $= Just mouse' and so on and so forth. Generally there are not fewer than 5 and not more than about 32 variables that I have to track between mouse clicks, and there's all this boilerplate code as well. I'm searching for a better way to do this, and I feel sure there is one. I'm considering using Template Haskell or possibly SYB to generate this code, but it also seems like I also ought to be able to declare some kind of state monad or continuation monad that can encapsulate ProgramState without having to declare an explicit structure for it everytime. For one thing, I'd like to genericize this code and write something akin to Processing for Haskell (http://www.processing.org). ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe signature.asc Description: OpenPGP digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Exceptions
Hello, I think it'd be nice if the compiler could warn me if there are any exceptions which I'm not catching, similar to checked exceptions in Java. Does anyone know of a possibility to do that in Haskell? Adrian PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Help with optimization
Maybe your image isn't strict enough and the computations are forced when the image gets written to disc? Am 20.07.2008 um 14:13 schrieb Mitar: Hi! Profiling says that my program spends 18.4 % of time (that is around three seconds) and 18.3 % of allocations in this function which is saving the rendered image to a PPM file: saveImageList :: String - Int - Int - [ViewportDotColor] - IO () saveImageList filename width height image = do B.writeFile filename file where file = B.append header bytes header = C.pack $ P6\n ++ show width ++ ++ show height ++ \n255\n bytes = B.pack $ concatMap (color . dealpha . (\(ViewportDotColor _ c) - c)) image where color (VoxelColor red green blue _) = [floor $ red * 255, floor $ green * 255, floor $ blue * 255] dealpha c = addColor c (VoxelColor 1.0 1.0 1.0 1.0) -- white background For a 921615 bytes large file to save this is too much in my opinion. And I think that it consumes to much allocations. Probably it should not store intermediate lists? Any suggestions? Best regards Mitar ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Fixed-Point Combinators
Hello, while studying for a exam I came across this little pearl: Y = (L L L L L L L L L L L L L L L L L L L L L L L L L L L L) where L = λabcdefghijklmnopqstuvwxyzr. (r (t h i s i s a f i x e d p o i n t c o m b i n a t o r)) posted by Cale Gibbard to this list. Now I'm wondering how exactly does one finde such awesome λ expressions? Is there some mathemagical background that lets one conjure such beasts? Adrian PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Compiling large code with old machine
I would assume -O0, that is, turning off all optimizations, should make compilation faster Adrian Am 17.06.2008 um 14:19 schrieb Samuel Silva: Hello I'm using GHC to compile around 700K of Haskell Code generated by HaXml. How I compile this code. My machine is Windows-XP(512MB RAM, 1.5GHz) running GHC-6.8.2. How much time it spend to compile this file? I spent more than 1 hour and it doesn't finished. What flags make compiling fast? I try with -H500m but dont't expect. It is possible GHC running endless cycle at compilation stage? Thanks. -- Don't hug that, Hugs ME! Samuel Silva ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] (no subject)
{- I downloaded the source and put my file in the same directory You may need to adjust the imports -} module Main where import Picture import Draw -- change xWin to 1000 and yWin to 700 for this to work import EnableGUI -- I use a Mac import SOE hiding (Region) import qualified SOE as G (Region) import Data.List import Random -- lines are not Shapes unfortunately linie = ((Shape $ Polygon [(-0.1,-0.01),(-0.1,0.01),(0.1,0.01), (0.1,-0.01)]), (-0.1,0), (0.1,0)) main = enableGUI do w - openWindow Lindenmayer System (xWin, yWin) newStdGen g - getStdGen drawPic w (aufgabe2 g) k - getKey w if (k=='q') then do closeWindow w return () else do clearWindow w main -- one big ugly line of code, not that interesting though aufgabe2 g= dasBild where r = rotateRegion (pi/2) $ Translate (-2.5,0) $ renderLSystem linie (lSystem 20 g) dasBild = Region White r `Over` Region Black ( Translate (0,-1.8) $ Scale (1,0.3)$ Translate (0,-2.6) $ rotateRegion (pi/2+pi/ 3) $ Translate (0,2.6) $ r) `Over` Region Green (Shape $ Polygon [(-5,-3.5),(-5,-1.5),(5,-1.5),(5,-3.5)]) `Over` Region Yellow (Translate (4,1.5) (Shape $ circle (0.5))) `Over` Region Blue (Shape $ Rectangle 14 7) -- start of the interesting part: -- A - Axiom, the base shape we use for rendering later --F - Forward --Branch - what it says data LSys = A LSys | F LSys | Branch StdGen [LSys] LSys | Done deriving Show -- a Axiom is a region with two connector points type Axiom = (Region, Vertex, Vertex) -- this seems not to be used anymore? scaleAxiom :: Float - Axiom - Axiom scaleAxiom f (r,u,v) = (Scale (f,f) r, f .*. u, f .*. v) -- just for testing purposes testLSys = A (Branch (mkStdGen 5) [A (F ((Branch (mkStdGen 5) [A (Branch (mkStdGen 5) [A (F ((Branch (mkStdGen 5) [A (F Done), A (F Done)] Done))), A (F Done)] Done), A (F Done)] Done))), A (F Done)] Done) -- a 2D rotation matrix drehM :: Float - (Float, Float, Float, Float) drehM w = (cos w, -sin w, sin w, cos w) -- matrix vector multiplication (.**.) :: (Float, Float, Float, Float) - Vertex - Vertex (.**.) (a,b,c,d) (px,py) = (a*px+b*py, c* px+d*py) -- other vector stuff (.-.) (a,b) (c,d) = (a-c,b-d) (.+.) (a,b) (c,d) = (a+c,b+d) (.*.) l (c,d) = (c*l,d*l) abs' (a,b) = (abs a, abs b) betr (a,b) = sqrt (a*a+b*b) -- SOE doesn't come with a way to rotate Regions, so I wrote my own rotateRegion :: Float - Region - Region rotateRegion f (Shape s) = Shape (rotateS f s) rotateRegion f (Translate v r) = Translate ((drehM f).**.v) (rotateRegion f r) -- the scaling part is not right I think. Everything seems to break if I try to incorporate scaling -- into the rendering rotateRegion f (Scale v r) = Scale ((betr v/ betr nv) .*. nv) (rotateRegion f r) where x = ((drehM f).**. (fst v,0)) y = ((drehM f) .**. (0,snd v)) nv = (abs' x) .+. (abs' y) rotateRegion f (Complement r) =Complement (rotateRegion f r) rotateRegion f (Union r1 r2) = Union (rotateRegion f r1) (rotateRegion f r2) rotateRegion f (Intersect r1 r2) = Intersect (rotateRegion f r1) (rotateRegion f r2) rotateRegion f (Xor r1 r2) = Xor (rotateRegion f r1) (rotateRegion f r2) rotateRegion _ s=s rotateS f (Polygon pts) = Polygon (map ((drehM f) .**.) pts) rotateS f x = x -- nondeterministically generate a word in our LSys language -- lots of copypaste here, any way to do this better? lSystem :: Int - StdGen - LSys lSystem n g = f n g (A undefined) where f :: Int - StdGen - LSys - LSys f 0 _ _ = Done f (n+1) g (A _) | choose = 1 = A (f n ng (F undefined)) | choose == 0 = A (f n ng (Branch ng [f n ng' (A undefined), f n ng'' (A undefined)] undefined)) where (choose, ng) = randomR (0::Int,3::Int) g (ng', ng'') = split ng f (n+1) g (F _) | choose = 1 = F (f n ng (F undefined)) | choose == 0 = F (f n ng (Branch ng [f n ng' (A undefined), f n ng'' (A undefined)] undefined)) where (choose, ng) = randomR (0::Int,3::Int) g (ng', ng'') = split ng f (n+1) g (Branch h lSys _) | choose = 1 = Branch h lSys (f n ng (F undefined)) | choose == 0 = Branch h lSys (f n ng (Branch ng [f n ng' (A undefined), f n ng'' (A undefined)] undefined)) where (choose, ng) = randomR (0::Int,5::Int) g (ng', ng'') = split ng -- recursivly render a LSys renderLSystem :: Axiom - LSys - Region renderLSystem _ Done = Empty renderLSystem (r,u,v) (A lSys) = r `Union` renderLSystem (r,u,v) lSys renderLSystem (r,u,v) (F lSys) = r'' `Union` renderLSystem (r'', u . +. o , v .+.o) lSys where r'' = Translate o $ r o = (v .-. u) renderLSystem (r,u,v) (Branch g lSys rest) = theBranches `Union` renderLSystem (r,u,v) rest where theBranches = Translate o $ foldr Union Empty $ -- we need to rotate around the u-Connector, not around (0,0) -- thus translation map
Re: [Haskell-cafe] Lindenmayer Systems, WAS: (no subject)
I screwed up the email, sorry about that. What I wanted to say was: Hello, as homework I was assigned to design and draw an image using the SOE Graphics library [1]. In order to impress my classmates I decided to draw a bush-like thingy using a Lindenmayer-System. It turns out quite nice [2], and so I thought I might share my code with you. Of course criticism is very welcome. Ok, here we go: {- I downloaded the source and put my file in the same directory You may need to adjust the imports -} module Main where import Picture import Draw -- change xWin to 1000 and yWin to 700 for this to work import EnableGUI -- I use a Mac import SOE hiding (Region) import qualified SOE as G (Region) import Data.List import Random -- lines are not Shapes unfortunately linie = ((Shape $ Polygon [(-0.1,-0.01),(-0.1,0.01),(0.1,0.01), (0.1,-0.01)]), (-0.1,0), (0.1,0)) main = enableGUI do w - openWindow Lindenmayer System (xWin, yWin) newStdGen g - getStdGen drawPic w (aufgabe2 g) k - getKey w if (k=='q') then do closeWindow w return () else do clearWindow w main -- one big ugly line of code, not that interesting though aufgabe2 g= dasBild where r = rotateRegion (pi/2) $ Translate (-2.5,0) $ renderLSystem linie (lSystem 20 g) dasBild = Region White r `Over` Region Black ( Translate (0,-1.8) $ Scale (1,0.3)$ Translate (0,-2.6) $ rotateRegion (pi/2 +pi/3) $ Translate (0,2.6) $ r) `Over` Region Green (Shape $ Polygon [(-5,-3.5),(-5,-1.5),(5,-1.5),(5,-3.5)]) `Over` Region Yellow (Translate (4,1.5) (Shape $ circle (0.5))) `Over` Region Blue (Shape $ Rectangle 14 7) -- start of the interesting part: -- A - Axiom, the base shape we use for rendering later --F - Forward --Branch - what it says data LSys = A LSys | F LSys | Branch StdGen [LSys] LSys | Done deriving Show -- a Axiom is a region with two connector points type Axiom = (Region, Vertex, Vertex) -- this seems not to be used anymore? scaleAxiom :: Float - Axiom - Axiom scaleAxiom f (r,u,v) = (Scale (f,f) r, f .*. u, f .*. v) -- just for testing purposes testLSys = A (Branch (mkStdGen 5) [A (F ((Branch (mkStdGen 5) [A (Branch (mkStdGen 5) [A (F ((Branch (mkStdGen 5) [A (F Done), A (F Done)] Done))), A (F Done)] Done), A (F Done)] Done))), A (F Done)] Done) -- a 2D rotation matrix drehM :: Float - (Float, Float, Float, Float) drehM w = (cos w, -sin w, sin w, cos w) -- matrix vector multiplication (.**.) :: (Float, Float, Float, Float) - Vertex - Vertex (.**.) (a,b,c,d) (px,py) = (a*px+b*py, c* px+d*py) -- other vector stuff (.-.) (a,b) (c,d) = (a-c,b-d) (.+.) (a,b) (c,d) = (a+c,b+d) (.*.) l (c,d) = (c*l,d*l) abs' (a,b) = (abs a, abs b) betr (a,b) = sqrt (a*a+b*b) -- SOE doesn't come with a way to rotate Regions, so I wrote my own rotateRegion :: Float - Region - Region rotateRegion f (Shape s) = Shape (rotateS f s) rotateRegion f (Translate v r) = Translate ((drehM f).**.v) (rotateRegion f r) -- the scaling part is not right I think. Everything seems to break if I try to incorporate scaling -- into the rendering rotateRegion f (Scale v r) = Scale ((betr v/ betr nv) .*. nv) (rotateRegion f r) where x = ((drehM f).**. (fst v,0)) y = ((drehM f) .**. (0,snd v)) nv = (abs' x) .+. (abs' y) rotateRegion f (Complement r) =Complement (rotateRegion f r) rotateRegion f (Union r1 r2) = Union (rotateRegion f r1) (rotateRegion f r2) rotateRegion f (Intersect r1 r2) = Intersect (rotateRegion f r1) (rotateRegion f r2) rotateRegion f (Xor r1 r2) = Xor (rotateRegion f r1) (rotateRegion f r2) rotateRegion _ s=s rotateS f (Polygon pts) = Polygon (map ((drehM f) .**.) pts) rotateS f x = x -- nondeterministically generate a word in our LSys language -- lots of copypaste here, any way to do this better? lSystem :: Int - StdGen - LSys lSystem n g = f n g (A undefined) where f :: Int - StdGen - LSys - LSys f 0 _ _ = Done f (n+1) g (A _) | choose = 1 = A (f n ng (F undefined)) | choose == 0 = A (f n ng (Branch ng [f n ng' (A undefined), f n ng'' (A undefined)] undefined)) where (choose, ng) = randomR (0::Int,3::Int) g (ng', ng'') = split ng f (n+1) g (F _) | choose = 1 = F (f n ng (F undefined)) | choose == 0 = F (f n ng (Branch ng [f n ng' (A undefined), f n ng'' (A undefined)] undefined)) where (choose, ng) = randomR (0::Int,3::Int) g (ng', ng'') = split ng f (n+1) g (Branch h lSys _) | choose = 1 = Branch h lSys (f n ng (F undefined)) | choose == 0 = Branch h lSys (f n ng (Branch ng [f n ng' (A undefined), f n ng'' (A undefined)] undefined)) where (choose, ng) = randomR (0::Int,5::Int) g (ng', ng'') = split ng -- recursivly render a LSys renderLSystem :: Axiom - LSys - Region renderLSystem _ Done = Empty renderLSystem (r,u,v) (A lSys) = r `Union` renderLSystem (r,u,v) lSys
Re: [Haskell-cafe] cgi liftM liftIO
I think you need to put liftIO in front of the IO actions you want to do inside the CGI Monad. Like in this example http://www.haskell.org/haskellwiki/ Practical_web_programming_in_Haskell#File_uploads (Why did I need to use google to find that? The wiki search in awful. Searching for CGI returns nothing, whereas with google the above is the first hit.) Am 13.06.2008 um 15:41 schrieb Cetin Sert: Hi, Could someone please care to explain what I am doing wrong below in cgiMain2 and how can I fix it? ./Main.hs:25:15: No instance for (MonadCGI IO) arising from a use of `output' at ./Main.hs:25:15-20 Possible fix: add an instance declaration for (MonadCGI IO) In the first argument of `($)', namely `output' In the expression: output $ renderHtml $ page import fileForm In the definition of `upload': upload = output $ renderHtml $ page import fileForm ./Main.hs:57:29: Couldn't match expected type `CGI CGIResult' against inferred type `IO CGIResult' In the first argument of `handleErrors', namely `cgiMain2' In the second argument of `($)', namely `handleErrors cgiMain2' In the expression: runCGI $ handleErrors cgiMain2 import IO import Network.CGI import Text.XHtml import qualified Data.ByteString.Lazy as BS import Control.Monad (liftM) import Data.Maybe (fromJust) import Interact fileForm = form ! [method post, enctype multipart/form-data] [afile file, submit Upload] page t b = header thetitle t +++ body b cgiMain1 = do getInputFPS file ↠ λms → maybe upload contents ms ↠ return where upload = output $ renderHtml $ page import fileForm contents = outputFPS cgiMain2 = do getInputFPS file ↠ λms → maybe upload contents ms ↠ return where upload = output $ renderHtml $ page import fileForm contents = λs → do (i,o,h,_) ← runUnzip BS.hPutStr i s c ← BS.hGetContents o outputFPS c {- (i,o,h,_) ← runUnzip BS.hPutStr i s BS.hGetContents o ↠ outputFPS -} {- liftM :: (Monad m) = (a1 - r) - m a1 - m r liftIO :: (MonadIO m) = IO a - m a saveFile n = do cont - liftM fromJust $ getInputFPS file let f = uploadDir ++ / ++ basename n liftIO $ BS.writeFile f cont return $ paragraph (Saved as +++ anchor ! [href f] f +++ .) -} runUnzip = runInteractiveCommand unzip -l /dev/stdin main = runCGI $ handleErrors cgiMain2 Best Regards, Cetin Sert P/s: what are lifts o_O? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Copying Arrays
Isn't fast IO what ByteStrings where invented for? Adrian Tom Harper schrieb: I'm trying to implement some file I/O where I can read in a file to an array, but do so without having to know how much space I will need. (Before you suggest it, lists are too slow/space consuming.) I was thinking that one possible solution is to use a strategy used in dynamic arrays, where everytime you run out of space you double the capacity of the array. Trouble is, most arrays in Haskell would require you to traverse the entire array and copy each individual cell, which would make it worthless. Are there any low-level array types (MutableByteArray#, for example) that support a memcpy-like function where I could copy the entire array into the new one instead of copying it one value at a time? Is there another solution that I'm missing? signature.asc Description: OpenPGP digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] appending an element to a list
Hello, I was wondering how expensive appending something to a list really is. Say I write I'd say longList ++ [5] stays unevaluated until I consumed the whole list and then appending should go in O(1). Similarly when concatenating two lists. Is that true, or am I missing something? Adrian signature.asc Description: OpenPGP digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HTTP and file upload
Yes http://hpaste.org/6990 Am 14.04.2008 um 19:07 schrieb Adam Smyczek: Is form based file upload supported in HTTP module (HTTP-3001.0.4)? Adam ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Windows CE, Xscale Compiler?
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 signature.asc Description: OpenPGP digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] HDBC, character encoding
Hi, I wrote a CGI program to access a Postgres database using HDBC. The database stores books and I want to display those from a certain author. Everything works fine, unless I search for someone with an umlaut in his name. Böll, for example. I have a function like this bookByAuthor :: Connection - AutorName - IO [[String]] bookByAuthor c aName = do writeFile ./err.log ((show aName)++ ++(show $ toSql aName)) rows - quickQuery c SELECT * FROM buecher WHERE lower (autor_name) LIKE ? ORDER BY autor_name, buch_name [toSql $ map toLower $ '%':aName++%] return $ map (map fromSql) rows It returns me a SqlError. However, doing the same in ghci works perfectly. I can't understand why. err.log contains b\195\182ll SqlString b\195\182ll which is ok I think. Since quickQuery c SELECT * FROM buecher WHERE lower(autor_name) LIKE ? ORDER BY autor_name, buch_name [toSql %b\195\182%] works in ghci. I have tried b\246ll, but that doesn't even work in ghci, although the database-encoding is utf-8. This all is really annoying... Adrian PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Performance Issues
Hello Haskell-Cafe! I've read about Control.Parallel and wanted to give it a try. Here's what I wrote: --- import Control.Parallel import Data.List splitList :: [Integer] - [[Integer]] splitList = unfoldr f where f [] = Nothing f ~x = Just (splitAt 3 x) map' :: (a-b) - [a] - [b] map' f (x:xs) =fx `par` (seq mfxs (fx:mfxs)) where fx = f x mfxs = map' f xs map' f [] = [] product' :: [Integer] - Integer product' = foldr1 (\x y - seq x (x*y)) fak :: Integer - Integer fak n = product' $ map' product' (splitList [1..n]) main = putStrLn $ seq (fak 100) done --- This computes 100!. This version takes 8m29.189s to execute. Replace foldr1 with foldr and that goes down to 7m4.315s. Replace product' with the Prelude product and it takes only 6m17.685s. Why is that so? I'm using ghc 6.8.1 on Mac OS X. Regards, Adrian PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] type trickery
Hello haskell-cafe! After making data Number = Zero | Succ Number an instance of Integral, I wondered how I could do the same with galois fields. So starting with Z mod p, I figured I'd need something like this data GF = GF Integer Integer so that each element of the finite field would remember p. However I can't think of a way to use the typesystem to ensure that p is always the same. I think that would need an infinite number of different types, but the type hackers here probably know something better. Adrian PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Trees
Good morning, as an exercise for my Algorithms and Programming course I have to program a couple of simple functions over trees. Until now everything we did in Java could be done in Haskell (usually much nicer too) using the naive data Tree a = Leaf a | Node a [Tree a] But now the assignments require more than a simple top-down traversal. For example: given a tree t and two nodes u,v, find the first common ancestor. In Java this is really simple, because each node has a parent reference. That way I only need to follow those references until I find the first common ancestor. This should take something like O(log n) in the average case. In Haskell however the best way I've come up with so far is doing a BFS and looking for the last common node in the paths to u and v. This is neither fast, nor particularly elegant. So how would you smart guys do it? With a Zipper? It would be nice if there was an elegant solution without monads. --Adrian PGP.sig Description: Signierter Teil der Nachricht ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Monad.Reader 8: Haskell, the new C++
-BEGIN PGP SIGNED MESSAGE- Hash: RIPEMD160 I heard only rumors, but isn't Lisp supposed to be just that? A programmable programming language? Peter Verswyvelen schrieb: This is all very cool stuff, but sometimes I wander if it isn't possible to drop the special languages for fiddling with types, and introduce just a single language which has no types, only raw data from which you can built your own types (as in the old days when we used macro assemblers ;-), but the language has two special keywords: static and dynamic, where code annotated with static runs in the compiler domain, and code annotated with dynamic runs in application domain. Of course, I don't know much about this, so this idea might be totally insane ;-) Probably this is impossible because of the halting problem or something... Pete Don Stewart wrote: Better here means better -- a functional language on the type system, to type a functional language on the value level. -- Don For a taste, see Instant Insanity transliterated in this functional language: http://hpaste.org/2689 NB: it took me 5 minutes, and that was my first piece of coding ever with Type families Wow. Great work! The new age of type hackery has dawned. -- 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 -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFG6ikc11V8mqIQMRsRA+PzAKCN0bC6lv8p9WEwJkJrcczktIdKGACfUdkt 0QBGlmgwfYrKS6lKEwQihkc= =31jo -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Data.Binary Endianness
-BEGIN PGP SIGNED MESSAGE- Hash: RIPEMD160 I try to write a Windows Bitmap File using Data.Binary, but I have some trouble. For example, the internet states, that the magic number, that puts 'BM' in the first two bytes of the file is 19778. But when I put (19778::Word16) I get 'MB' instead. I read on the german Wikipedia, that bmp uses little endian encoding, but Data.Binary uses big endian. Obviously this can't work. Is there a way to switch endianness? Or at least a function that converts between the two? I looked at the Data.Binary Haddock documentation, but found nothing like that. Thanks in advance, Adrian -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFG5Q1Z11V8mqIQMRsRA/V6AJoC/R2k5rz0LjQI4iGoi79zLYZmgwCdEx/g cZOR5jseUcQnc6+I09N+xj8= =K5ww -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] IO inside CGI
-BEGIN PGP SIGNED MESSAGE- Hash: RIPEMD160 I'm toying around with web programming in Haskell. I'm trying to write a script which GETs an id and returns a couple of random numbers. Something like this: cgiMain :: CGI CGIResult cgiMain = do inp - getInput id let gen = parse inp output $ take 10 (randoms gen) parse :: Maybe String- StdGen parse (Just x) = read x parse Nothing = undefined Now I'd like to get a new StdGen, in case no id was supplied to the script. cgiMain :: CGI CGIResult cgiMain = do inp - getInput id gen - parse inp output $ take 10 (randoms gen) parse :: Maybe String- IO StdGen parse (Just x) = return $ read x parse Nothing = getStdGen Obviously this doesn't work because I'm trying to do IO inside CGI (right?). Is there some incantation I can perform to make this possible? Like gen - arcaneMagic parse inp As you probably have noticed I don't know very much about monads, all I did until now was reading or writing some files. Thanks in advance -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGzudU11V8mqIQMRsRA33RAJ9buZDHgz/eXi8Jw9OBwbTErDccRgCfbGrr 1WXiGHmxlTBe01E409yJyv8= =XSDj -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Sudoku Solver
-BEGIN PGP SIGNED MESSAGE- Hash: RIPEMD160 Hi, I wrote a brute-force sudoku solver. It takes a [[Int]] and spits out the first solution it finds. Why is it, that [0,0,0,7,0,6,9,0,0] [9,0,0,0,0,4,7,0,0] [7,0,0,0,0,0,4,0,0] [0,2,7,0,3,5,8,0,0] [6,9,5,8,2,0,0,0,0] [0,8,0,0,0,0,5,0,0] [0,3,0,0,0,0,0,0,0] [8,7,0,9,0,0,0,0,0] [0,0,0,0,0,0,0,0,0] is solved instantly, but when I remove just one number my program takes forever? === import Array import List import System type Field = Array Int (Array Int Int) isEmpty :: Int - Bool isEmpty = (==) 0 done :: Field - Bool done a = isFull a checkField a isFull::Field - Bool isFull a = notElem (0) $ (concat.(map elems).elems) a readField :: [[Int]]-Field readField = (listArray (1,9).map (listArray (1,9))) checkField :: Field - Bool checkField a = check (rows a) check (columns a) check (squares a) where check b = and $ ((map ((==1).length)).concat.(map group).clean) b clean = map (dropWhile isEmpty.sort) columns::Field - [[Int]] columns a = [[a!i!j|i-[1..9]]|j-[1..9]] rows :: Field - [[Int]] rows a = [[a!i!j|j-[1..9]]|i-[1..9]] squares :: Field - [[Int]] squares a = [[a!(i+n)!(j+m)|i-[1..3],j-[1..3]] |n-[0,3,6],m-[0,3,6]] - -- creates a list of all allowed entries genMoves :: Field - [Field] genMoves a = concat [update a i j|i-[1..9],j-[1..9],isEmpty (a!i!j)] where update b i j= [b //[(i,b!i //[(j,x)])]|x-[1..9], checkField (b //[(i,b!i //[(j,x)])])] play :: [Field] - Maybe Field play (f:a) | done f= Just f | isFull f= play a | otherwise = play ((genMoves f)++a) play [] = Nothing main :: IO () main = do x - getArgs let field = read (x!!0) :: [[Int]] let erg=play [readField field] case erg of Just a - putStrLn $ concat $ map ((++\n).show) (rows a) Nothing - putStrLn Es gibt keine Loesung -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGtx0r11V8mqIQMRsRA7P5AJ9lG3mF3fHpUiyOqCeRVOOEGozp1wCeI80C RfD/U5y+yEgF0fe+kRwDbUI= =Ngss -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Cannot compile Network.CGI programs
-BEGIN PGP SIGNED MESSAGE- Hash: RIPEMD160 Hi, I installed the Network.CGI package and tried to compile the Hello World example on my Ubuntu machine. ghc cgi.hs -o cgi gives me cgi.o: In function `r1hk_info': (.text+0x56): undefined reference to `mtlzm1zi0_ControlziMonadziTrans_zdf1_closure' cgi.o: In function `r1hm_info': (.text+0xb6): undefined reference to `cgizm2006zi9zi6_NetworkziCGIziMonad_zdf4_closure' cgi.o: In function `r1ho_info': (.text+0x11a): undefined reference to `cgizm2006zi9zi6_NetworkziCGI_runCGI_closure' cgi.o: In function `r1ho_info': (.text+0x121): undefined reference to `mtlzm1zi0_ControlziMonadziTrans_zdf1_closure' cgi.o: In function `r1hq_info': (.text+0x17e): undefined reference to `cgizm2006zi9zi6_NetworkziCGI_output_closure' cgi.o: In function `s1hE_info': (.text+0x2aa): undefined reference to `cgizm2006zi9zi6_NetworkziCGI_handleErrors_closure' cgi.o: In function `r1hk_srt': (.rodata+0x0): undefined reference to `mtlzm1zi0_ControlziMonadziTrans_zdf1_closure' cgi.o: In function `r1hm_srt': (.rodata+0x4): undefined reference to `cgizm2006zi9zi6_NetworkziCGIziMonad_zdf4_closure' cgi.o: In function `r1ho_srt': (.rodata+0xc): undefined reference to `cgizm2006zi9zi6_NetworkziCGI_runCGI_closure' cgi.o: In function `r1ho_srt': (.rodata+0x10): undefined reference to `mtlzm1zi0_ControlziMonadziTrans_zdf1_closure' cgi.o: In function `r1hq_srt': (.rodata+0x14): undefined reference to `cgizm2006zi9zi6_NetworkziCGI_output_closure' cgi.o: In function `s1hE_srt': (.rodata+0x38): undefined reference to `cgizm2006zi9zi6_NetworkziCGI_handleErrors_closure' collect2: ld gab 1 als Ende-Status zurück However runghc cgi.hs produces a Hello World Content-type: text/html; charset=ISO-8859-1 Hello World! Why is that so? What can I do to compile CGI-programs? (GHC 6.6, libghc6-cgi-dev 2006.9.6-3) -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGV+k211V8mqIQMRsRA62mAKCW0lp+zeniR+3Mi12+9dzRFMZm6QCaArpd R67KMtScgzFFDV0+GDbH75A= =Wuax -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Intermediate Haskell Books?
-BEGIN PGP SIGNED MESSAGE- Hash: RIPEMD160 Are there any good books about intermediate to advanced Haskell? The descriptions here http://haskell.org/haskellwiki/Books_and_tutorials aren't very helpful. Adrian -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGPZCo11V8mqIQMRsRA8nVAJ9fs4c013qKOuEjX//uLW3hLTYtxACfTS/t 5D6I+/OGifs3ltYhx6rwFZA= =sNJP -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] The Trivial Monad
-BEGIN PGP SIGNED MESSAGE- Hash: SHA512 I've read this blogpost about the trivial monad http://sigfpe.blogspot.com/2007/04/trivial-monad.html, because I still don't understand what this monad thingy is all about. The author defines three functions: data W a = W a deriving Show return :: a - W a return x = W x fmap :: (a - b) - (W a - W b) fmap f (W x) = W (f x) bind :: (a - W b) - (W a - W b) bind f (W x) = f x and asks the reader to prove the tree monad laws for them. However I don't understand the type signatures for bind and fmap. I'd say (and ghci's type inference agrees) that bind and fmap have the type bind:: (a-W b) - W a - W b fmap:: (a-b) - W a - W b They take a function f and something and return what f does to that. I don't see why they should return a function. This of course makes it hard for me to prove the monad laws. The first however works nonetheless: 1) bind f (return a)= f a = bind f (return a)= bind f (W a) = f a Can someone explain bind and fmap (and possible law 2 and 3)? Thanks, Adrian -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGOuQS11V8mqIQMRsRCmngAJ9NwQMwXeS/PSM1NUsVA8gxPuA0KACfSLiA ItqRZW5a4XyQ099bhMtSWmU= =/8i/ -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] (newbie) instance Enum MyType where, smarter way?
-BEGIN PGP SIGNED MESSAGE- Hash: RIPEMD160 Hello, I defined an enumeration datatype like this data MyType = One | Two | Four | Eight and want to make it an instance of the class Enum. deriving Enum won't do what I want, as it labels the items 0,1,2,3. Is there a better way to do this than instance Enum MyType where fromEnum One = 1 fromEnum Two = 2 ... toEnum 8 = Eight Something like instance Enum MyType where fromEnum One = 1 fromEnum x = 2*pred x toEnum 1 = One toEnum x = succ (toEnum x `div` 2) Which doesn't work because succ and pred are not (properly?) defined. Is there a way to let deriving Enum do *some* of work (i.e. defining succ and pred) while manually defining the other functions? -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGCTRJ11V8mqIQMRsRA4GFAJwKaxQoKdEW91pHUskzJadDvh7lXgCeLg6P dmQKcjRZEg4fqoZfQ4jOuhg= =RWQ+ -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe