[Haskell-cafe] Those damned parentheses
Hi. I am kind of tired of all of the parentheses I have to put in places and I'm trying to figure out what is the correct way to write code such that I can leave out parentheses. For example, I have the following: data Message = ... --leaving this out because it's not important data Plane = Plane { id :: Int, position:: (Int,Int,Int), direction :: Int, path:: [Int], messagebuf :: Chan Message } main = do c - newChan :: Chan Message p - Plane 0 (0,0,0) 0 [] c f p f p = putStrLn $ (show Main.id p) ++ - message received This causes an error The function `show' is applied to two arguments. If I put instead: f p = putStrLn $ (show . Main.id p) ++ - message received I get the error Couldn't match expected type `[Char]' with actual type `a0 - c0'. The only way it seems to work is f p = putStrLn $ (show (Main.id p)) ++ - message received This seems to be the same for many other situations where I try to use function composition of some sort. It's just getting kind of annoying. -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Those damned parentheses
I know about the $ symbol, that's why it's in there in the respective places. I see that I can use it to fix my problem, but I was trying to figure out function composition really. I guess that's just not the place for it. I'll check out Control.Applicative. Also thanks for the clarification on function application. I know functions are by default infixl 9, but I hadn't really thought that through all the way. -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Documentation for OpenGL?
Hi everyone. I'm looking for something specific. I'm trying to figure out how to use the depthFunc StateVar and I can't find any official documentation for it. I did a :t depthFunc in ghci and got depthFunc :: StateVar (Maybe ComparisonFunction) so I looked up ComparisonFunction and couldn't find anything official on that either. Is there any documentation for it? Maybe I wasn't looking in the right places? Thanks in advance. -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Documentation for OpenGL?
Woops, nevermind. I WAS looking in the wrong place. I should've known =P. Sorry for the unnecessary request. -Eitan PS. For anyone interested all of the documentation is in Graphics.Rendering.OpenGL.GL.PerFragment on hackage ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Compiled OpenGL program has DOS window?
Hi. I'm working in Windows on an OpenGL application. I finally got everything working, doing all of my testing through the interpreter. When I finally compiled and ran the program from an executable for the first time I noticed that before creating my OpenGL window an empty DOS prompt popped up. I think I understand why the computer would want to do that, but I don't know how to make it stop. I've done some OpenGL in C++ and I remember having a similar problem. If I remember correctly the problem was fixed with a compiler flag. I'm using GHC and I looked through their compiler flags, but I didn't find anything that looked like it would deal with this. Anyone have any ideas? -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] How do you change the mouse position?
In C++, maybe Java, I remember using a Robot to change the location of the mouse on the screen. My intention is to do something like in an FPS game where the mouse is always centered to make sure it doesn't run into the edges of the screen. How can I do that in Haskell? I'm using OpenGL, so if there is a utility that specifically works with OpenGL then I believe that would be the most helpful. -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How do you change the mouse position?
Thanks. That is exactly what I was looking for. I really appreciate the help. -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Fail to install SDL with Cabal
I'm trying to install SDL through Cabal -- I don't know another way to install it. However, I'm getting this: setup.exe: The package has a './configure' script. This requires a Unix compatibility toolchain such as MinGW+MSYS or Cygwin. cabal: Error: some packages failed to install: SDL-0.5.10 failed during the configure step. The exception was: exit: ExitFailure 1 I have MinGW and MSYS, so I don't understand why I'm having this problem. Do I need to set something special up so that Cabal can access their tools? -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] OpenGL Speed!
HGL actually looks like EXACTLY what I need. I only need to set pixels, which looks like just what HGL would be good at. Only problem is that I can't find a single tutorial for HGL. Does anyone know or any, or where I could find one? -Eitan On 7/30/2010 12:22 PM, Henning Thielemann wrote: Vo Minh Thu schrieb: There other possibilities to deal with raster graphics: - Use gtk; i.e. something like http://hackage.haskell.org/package/AC-EasyRaster-GTK - Output the data in some image format (if you want to do it yourself, the most simple is PPM) - Use X11 directly (if you're on unix) - ... or good old HGL: http://hackage.haskell.org/package/HGL ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] OpenGL Speed!
I'm having an unusual problem with OpenGL. To be honest I probably shouldn't be using OpenGL for this, as I'm just doing 2D and only drawing Points, but I don't know about any other display packages, so I'm making due. If this is a problem because of OpenGL however, then I'll have to learn another package. The problem is speed. I have a list of points representing the color of 800x600 pixels. All I'm trying to do is display the pixels on the screen. I use the following: renderPrimitive Points $ mapM_ display list flush where display [] = return () display ((x,y,i):n) = do color $ Color3 i i i vertex $ Vertex2 x y display n But, for some reason this takes FOREVER. I don't know how to use debugging hooks yet without an IDE -- and I don't use an IDE -- but I used a cleverly placed putStrLn to see that it was actually working, just really really slowly. Is there a solution to this speed problem or should I use a package that's more suited to 2D applications like this? Also, if I should use another package, are there any suggestions for which to use? Thanks for any help. -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Memory and Threads - MVars or TVars
Hi everyone. I was wondering if someone could just guide me toward some good information, but if anyone wants to help with a personal explanation I welcome it. I'm trying to write a threaded program and I'm not sure how to manage my memory. I read up on MVars and they make a lot of sense. My real question is what is atomic and how does it apply to TVars? I don't understand what atomic transactions are and I can't seem to find a concise explanation. I also saw some stuff about TMVars? But I can't find much on them either. Any help would be appreciated. -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Memory and Threads - MVars or TVars
I can't believe I never knew about Cabal. I'm getting Orc now. It looks very interesting. Thanks for the help. -Eitan On 7/28/2010 9:17 PM, Günther Schmidt wrote: Hi Eitan, I'm right now approaching the subject of concurrency myself for the first time in an application that spiders web pages. The getting the web pages part via http request is the one that is time consuming and thus the one that I wish to concurrentalize, ie. getting up to 6 six pages concurrently at a time. From what I've learned so far it seems that there are the following approaches to concurrency in haskell: 1. use a primitive approach with the concurrency primitives that haskell / ghc provides, ie. locks, MVars, TVars etc. directly 2. use one abstraction level up, ie. use STM (Software Transactional Memory), there is a chapter in RWH about it.(also available online). 3. use yet another abstraction level up by using the orc library from the galois people, available on hackage. Documentation to this one is a paper available on the galois website. I am currently at the very beginning of familiarizing myself with this approach but it seems the most feasible way to do concurrency. Using this approach is pretty much like not having to worry about garbage collection. Even using STM you still have to do a lot of your own manual forkIO, putVar, kill etc. Best regards Günther Am 29.07.10 02:23, schrieb Eitan Goldshtrom: Hi everyone. I was wondering if someone could just guide me toward some good information, but if anyone wants to help with a personal explanation I welcome it. I'm trying to write a threaded program and I'm not sure how to manage my memory. I read up on MVars and they make a lot of sense. My real question is what is atomic and how does it apply to TVars? I don't understand what atomic transactions are and I can't seem to find a concise explanation. I also saw some stuff about TMVars? But I can't find much on them either. Any help would be appreciated. -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Memory and Threads - MVars or TVars
Ah! That clears that up a lot. I read the wiki page but something just didn't make full sense about it until you used the word prevent. I understand that the computer doesn't actually prevent other threads from running -- that would defeat the purpose of the concurrency -- but it helped clear it up. Perhaps you guys could help me with Cabal now though? I'm trying to install Orc but it wants base=4.2 and =4.3 and I have 4.1 after installing the latest release of GHC. Cabal won't upgrade the base. It complains about a dependency to integer-simple. Anyone know what that's about? -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] The where-clause and guards
I'm trying to fit a where clause to some guards I'm using. I have the following f a b | c 1 = ... | c 1 = ... | otherwise = ... where c = a+b yet I'm getting a parsing error. Is this not the correct way to combine where with guards? -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] The where-clause and guards
Well, perhaps you can help me figure out the problem with my exact program. Just in case it matters, the program draws a Mandelbox via volumetric ray casting. I can provide more information about the function, but I wouldn't think it's necessary, since my problem is with parsing. The error I'm getting is with the where-clause at the very bottom: traceRay (x,y) r@((cx,cy,cz):n) (vx,vy,vz) iter | m 100= do color $ Color3 (sin vx) (cos vy) (cos vz) vertex $ Vertex2 x y | otherwise = do [boxx,boxy,boxz] - boxFold [vx,vy,vz] (ballx,bally,ballz) - ballFold (boxx,boxy,boxz) traceRay (x, y) r (2*ballx + cx, 2*bally + cy, 2*ballz + cz) (iter-1) where boxFold [] = return [] boxFold (a:b) | a 2= do rem - boxFold b return $ (2-a):rem | a (-2) = do rem - boxFold b return $ (-2-a):rem |otherwise = do rem - boxFold b return $ (a):rem ballFold (x,y,z) | n 0.5 = return (4*x, 4*y, 4*z) | n 1 = return (x/(n*n), y/(n*n), z/(n*n)) | otherwise = return (x, y, z) where n = sqrt $ x*x + y*y + z*z where m = sqrt $ vx*vx + vy*vy + vz*vz On 7/21/2010 3:13 AM, Nicolas Wu wrote: There's nothing wrong with the use of your example, I'm guessing it's something in your ... that's leading to the parse error. This compiles just fine: f a b | c 1 = 1 | c 1 = 2 | otherwise = 3 where c = a+b Nick ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] The where-clause and guards
Aha. I understand now. A single where-clause applies to the entire scope of the function, at all levels. Thanks for the help. -Eitan On 7/21/2010 3:55 AM, Nicolas Wu wrote: Ugh, my formatting got eaten up by gmail. I just removed the where in front of m =, and aligned tat statment with your ballFold definition. I would also align the first where statement with the case bars of traceRay. Nick On Wed, Jul 21, 2010 at 8:53 AM, Nicolas Wunicolas...@gmail.com wrote: ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How do you make constant expressions?
One point of clarification that'd be nice. I'm getting some type errors that I wasn't getting before, so I'd just like to know something about the inline pragma. I have width = 800 {-# INLINE width #-} main = (truncate width, fromIntegral width) Now when I ran this program it seemed to work at first. Note that truncate and fromIntegral take different types as inputs. I then changed a different part of the program having nothing to do with this code and all of a sudden GHC started giving me a type error about the above code. Does anyone know why? -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How do you make constant expressions?
Correction to my last e-mail. I figured out why it worked at first and then failed, so I'll refine my question. I'd like the compiler to simply put the number 800 everywhere that I put the name width in my code. Instead it's putting (800 :: Float), or Double or Int, whatever I want, but it's restricted to one data type. I want to remove that restriction since it is a constant. -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How do you make constant expressions?
Awesome. It worked. Haskell continues to impress me. Thanks for the help everyone. -Eitan On 7/19/2010 4:42 AM, Max Bolingbroke wrote: Use NoMonomorphismRestriction or give an explicit type signature: width :: Num a = a width = 800 Max ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] How do you make constant expressions?
Silly question, but I can't find the answer on the net. I think I'm just using the wrong words in my search. I'm looking for a way to create constant expressions in Haskell. The C/C++ equivalent of what I'm talking about is #define NAME VALUE I want an expression, or really just numbers for what I'm doing, that the compiler will put into the program at the designated places, instead of storing it in memory like a variable. -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How do you make constant expressions?
So just so I get this straight, the following are equivalent to the computer, after compiling: 1. fact = 10 {-# INLINE fact #-} func x = x * fact 2. func x = x * 10 I'm also curious as to what the {-# #-} brackets represent. I've never seen those before. -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Devices and Webcams, The Basics
Ah thanks. Just what I'm looking for. Also thanks for the info about the USB bindings -Eitan On 5/20/2010 12:06 PM, Tom Nielsen wrote: OpenCV and its Haskell bindings http://hackage.haskell.org/package/HOpenCV should be able to talk to a webcam. There's an O'Reilly book about OpenCV. Tom On Wed, May 19, 2010 at 10:06 PM, Eitan Goldshtrom thesource...@gmail.com wrote: Hi everyone, I would like to start working on a program that requires access to a camera attached to the computer probably via USB or otherwise internally. Unfortunately I don't know anything about using devices in haskell. I tried looking up how to access the microphone one too and had little success. Could someone just point me in the direction of tutorials for learning the basics of both devices in general as well as the webcam more specifically? The webcam is a bit more of a priority. -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Devices and Webcams, The Basics
Hi everyone, I would like to start working on a program that requires access to a camera attached to the computer probably via USB or otherwise internally. Unfortunately I don't know anything about using devices in haskell. I tried looking up how to access the microphone one too and had little success. Could someone just point me in the direction of tutorials for learning the basics of both devices in general as well as the webcam more specifically? The webcam is a bit more of a priority. -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Threads freezing
Hello fellow Haskell programmers, I seem to be having problems with some threads of mine. I wrote an OpenGL program that employs some threads (forkIO) in order to separate any calculations from the OpenGL code. At first it all seemed to be working just fine. Then I added some code for keyboard input to reset the program when you press 'r'. Since then my threads have been giving me problems. Just a second after the program starts all the calculations stop. The program is still running the code to display graphics (I tested this by putting putStrLn still displaying into the display function) but the threads that do all of the computation don't seem to return from their threadDelay, which is only a delay of 5000 microseconds. I tried getting rid of the code for keyboard input but the problem is still there. I tried to run the program on another computer and it ran just fine (without keyboard input). Does anyone have any idea what could be going on? Additionally, I just tried compiling it to an executable and it seems that when I run it from that it works fine, with the keyboard input too. So I'm guessing the problem is with the interpreter? I'm not really sure. Haskell is still pretty mysterious to me. -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Search a directory for files
Hi, I'm trying to make a program to make it easy to rename files in bulk. What I'm wondering is how to get a list of all files in a particular directory. I found System.Posix.Files and I'm planning on using the rename function in it for actually renaming, but I can't find an easy way to get all filenames in a particular directory. Does anyone know how to do it? -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Search a directory for files
Thanks. This looks like exactly what I was looking for. I feel silly for not finding it myself. =P -Eitan Gregory Crosswhite wrote: Look in System.Directory; specifically, getDirectoryContents should do what you want. You might also check out the FileManip package, which provides some convenient functionality for finding all files which match a particular pattern. Cheers, Greg On Dec 19, 2009, at 6:40 PM, Eitan Goldshtrom wrote: Hi, I'm trying to make a program to make it easy to rename files in bulk. What I'm wondering is how to get a list of all files in a particular directory. I found System.Posix.Files and I'm planning on using the rename function in it for actually renaming, but I can't find an easy way to get all filenames in a particular directory. Does anyone know how to do it? -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] HOpenGL and freeglut rendering problems
Hello. I'm new to this mailing list, so I apologize if this question is inappropriate for this list, but I've been looking for a solution to this problem for weeks and I've had no luck. I am trying to write a program with HOpenGL and freeglut, but I can't seem to get it to render. I'm running Ubuntu 9.10 on a DELL 1555 with an ATI Radeon HD 4500. Right now my program just creates a window with a black background. However, when I try to run the program I get the following error: Unable to create direct context rendering for window 'IGL' This may hurt performance. I've read that this is because of the fglrx driver. The driver uses indirect rendering for OpenGL, but freeglut requires direct rendering? Is there a way to force freeglut to function with indirect rendering? -Eitan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe