Re: [Haskell-cafe] Haskell / Functional Programmers Group in Madrid (Spain)?
Hello Alejandro, I was just searching the list to see if there are any Haskellers in Barcelona. I've been living in Spain for almost a year and a half and haven't been able to find at least one person who knows about Haskell nor functional programming. I'd like to extend Alejandro's query to Barcelona city as well. Are there any Haskell/Functional Programmers in Barcelona? Just as Daniel said, if I end up in Madrid for any reason I'll sure contact you and support this as well. Kind regards, Héctor Guilarte On Wed, Apr 10, 2013 at 8:46 PM, Daniel Díaz Casanueva dhelta.d...@gmail.com wrote: Hi Alejandro! It would be great if Spain would have a Haskell Group in the capital city. I am from Spain and I always begged for something like this. Unfortunately, I find myself in the United States and unable to help. But if, for any circumstances, I end up in Madrid, I'll be there to support this. Saludos de un malagueño, Daniel Díaz. On Wed, Apr 10, 2013 at 3:50 AM, Alejandro Serrano Mena trup...@gmail.com wrote: Hi, Is there any Haskell or functional programmers user group in the region of Madrid? If not, I think it could be a great idea to get to know each other, and share experiences. Furthermore, we could try to organize some meetings with presentations, hackatons and so on (my personal ambition is to be able to organize another ekmett Workshop as the Japanese one - http://comonad.com/reader/2013/japanese-workshop-1/). I know there is some locations along Madrid dedicated to open source promotion, like http://madridonrails.com/, and which we could use for these meetings. I'm really looking forward to hearing from you! PS: Maybe a bare Haskell group is not big enough (at least according to Haskellers.com), but a functional programmers one may well be. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- E-mail sent by Daniel Díaz Casanueva let f x = x in x ___ 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] BPMN and BPEL
Thank you for your advice, Actually, I'm not comfortable with C# at all... I'm gonna be learning it as I develop the application. Also helpful are various Haskell-inspired features added to C# in the last few years, making it feasible to port a large subset of Haskell to C# fairly directly. What kind of features are those you mention? I'd like to know in advance in order to search them before I start to do anything, even if I'm not going to use Haskell, knowing those features might help me to get a high level of abstraction in C# (or not). On Wed, Sep 8, 2010 at 4:46 PM, C. McCann c...@uptoisomorphism.net wrote: On Wed, Sep 8, 2010 at 3:38 PM, Hector Guilarte hector...@gmail.com wrote: If somebody can point out really good reasons on why I should use Haskell to do my work, please let me know them, they might help me convincing my bosses. On the other hand, if you believe Haskell is a bad language for this kind of task, and why C# or any other .NET language would be better, I'm welcome to hear your reasons, they might convince me. Well, how comfortable are you with Haskell? If you're roughly as proficient in it as you are in C#, you could probably bang out a prototype using Haskell in a fraction of the time with fewer bugs. Most software projects get massively revised from the initial version anyway, so using a more productive language and then rewriting for the production version can still be a net win, especially since you can use the prototype as a specification or reference implementation (e.g., you get some QA for free by running the two on identical input and checking for identical output). And of course, maintenance and scalability don't matter in a prototype. If it goes well, you'll have proven that Haskell has value (without forcing a long-term, up-front commitment to it), probably improved the quality of the C# version, and gotten the chance to write Haskell at work. Furthermore, in this particular case, you say it's a mapper between data description languages. While I obviously don't know the details, applying transformations to complex, easily-inspected data structures is a classic example of a problem ideally suited to a functional language with pattern matching, be it Haskell, F#, or any other ML-influenced language--thus making Haskell even more advantageous for rapid prototyping. Also helpful are various Haskell-inspired features added to C# in the last few years, making it feasible to port a large subset of Haskell to C# fairly directly. - C. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] BPMN and BPEL
Hello, Does anybody knows if there is some work related to BPMN and/or BPEL done in Haskell? Maybe some research or some papers? I'm about to begin a mapper from BPMN to BPEL and Haskell is my first option for doing it, but since my company is somehow married to .NET and nobody else knows anything about Functional Programming or Haskell, using it might be a problem for maintenance and scalability. If somebody can point out really good reasons on why I should use Haskell to do my work, please let me know them, they might help me convincing my bosses. On the other hand, if you believe Haskell is a bad language for this kind of task, and why C# or any other .NET language would be better, I'm welcome to hear your reasons, they might convince me. I know about F#, but the problem is not that Haskell is not .NET, the problem is that it is functional programming and as I said before, nobody here knows a bit about it. If I were to do it using FP, I would use Haskell for sure, not F#. Thank you very much, Héctor Guilarte ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Mapping a Texture in OpenGL?
Hello, I already send this to the HOpenGL list, but I'm kind of in a hurry with this and I'll probabbly get more responses from you... I've been looking for a way to map a texture into a Quad primitive with HOpenGL with no luck. I've already done this in C++ and had no problem. I did the tutorial in http://www.haskell.org/~pairwise/HOpenGL/HOpenGL.html, downloaded the sources, compiled them and it worked great (After changing a 2 lines to make it work with OpenGL's latest version), but when I change the code to use a .rgb file created by me with the program they provide from a .png file of 256x256 pixels I don't have the same luck... My OpenGL version is 2.4.0.1... I'm REALLY lost, clueless, so any kind of help would be greatly appreciated. I checked the textures in the examples of the red book, but they are procedural textures, and I need to map an image. One of the pictures I need to map is in http://dl.dropbox.com/u/1476919/Orange256.png Are six like that one and are for making a Rubik's Cube. After I finish it I'll upload it to hackage and let you all know. Thanks a lot, Héctor Guilarte ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] does () match with a??
Hey! I just wanted to let you know I made it. I just changed the newtype declaration to: newtype Game r = Game { execGame :: Int - (Maybe r,Int) } and from there everything went just fine. Thank you for your responses, Hector Guilarte On Wed, Jul 7, 2010 at 9:24 PM, Hector Guilarte hector...@gmail.com wrote: On Wed, Jul 7, 2010 at 8:48 PM, John Meacham j...@repetae.net wrote: Are you sure you are interpreting what 'die' should do properly? Your code makes sense if die should decrement your life counter and continue along, however if 'die' is meant to end your whole game, then there is another implementation that does type check. John You're absolutely right, I sen't the wrong code, here's the correct one and a little bit more explanation about what checkpoint does. The result of die makes sense for the checkPoint function since there are three cases for it: 1) The player died and has no remaining lifes. The game can't continue, I just return Noting in the die function and in checkpoint make the corresponding case. 2) The player died and has remaining lifes. The game can be retried with a life subtracted. I would need to tell checkpoint that I died and I want to retry, that's where I think the result is important, because of the next case. 3) The player didn't died, it finished the particular game and checkpoint m equals m. Here I would need to see if the result of the game was different from the result from die, and continue. instance GameMonad Game where extraLife= Game $ \l - Just ((),l+1) getLives = Game $ \l - Just (l,l) die = do n - getLives if n = 0 then Game $ \_ - Nothing else Game $ \_ - Just (player died,n-1) checkPoint a = do n - getLives case execGame a n of Nothing - Game $ \_ - Nothing Just c - gameOn $ fst c where gameOn player died = a = \_ - (checkPoint a) gameOn _ = a Obviously this fails to compile because I'm returning a String and it doesn't match with a either, but the idea of what I think I need to do is right there. Ivan Miljenovic told me to use error, and actually I though something like that. in STM retry combined with atomically does something similar as what I need checkpoint and die to do, and they use exceptions to accomplish it. I really think that's the solution I want, but then I have another question, when I 'throw' the exception in die and 'catch' it in checkpoint to call it again, is the number of lives gonna be lives - 1? Thanks for answering so quickly, Hector Guilarte Pd: Here's an example run of how my homework should work after is finished printLives :: ( GameMonad m , MonadIO m ) = String - m () printLives = do n - getLives liftIO $ putStrLn $ s ++ ++ show n test1 :: ( GameMonad m , MonadIO m ) = m () test1 = checkPoint $ do printLives Vidas : die liftIO $ putStrLn Ganamos ! lastChance :: GameMonad m = m () lastChance = do n - getLives if n == 1 then return () else die test2 :: ( GameMonad m , MonadIO m ) = m String test2 = checkPoint $ do printLives Inicio n - getLives if n == 1 then do liftIO $ putStrLn Final return Victoria ! else do checkPoint $ do printLives Checkpoint anidado lastChance extraLife printLives Vida extra ! die AND THE OUTPUT TO SOME CALLS ghci runGameT test1 3 Vidas : 3 Vidas : 2 Vidas : 1 Nothing ghci runGameT test2 3 Inicio 3 Checkpoint anidado 3 Checkpoint anidado 2 Checkpoint anidado 1 Vida extra ! 2 Inicio 1 Finish Just ( Victoria ! ,1) -- John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/ ___ 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] does () match with a??
Hey everyone, I'm making a Game Monad for an assignment (yes, homework) . Here's a little explanation of what I need to do (I can't use anything from Control.Monad.*, I need to do everything myself): I need to define my newtype Game and make it's Monad instance I need to make the function : runGame :: Game a-- A particular game - Int -- Initial amount of lives - Maybe (a , Int ) -- Result and remaining lives. I need to make the instance for this class: class Monad m = GameMonad m where extraLife :: m () getLives :: m Int checkPoint :: m a - m a die:: m a now what I've done (I was inspired by the State Monad) I defined my Game type as follows: newtype Game r = Game { execGame :: Int - Maybe (r,Int) } My Monad instance like this: instance Monad Game where return a = Game $ \r - Just (a,r) m = k = Game $ \r - let x = execGame m r in case x of Just (a, r') - execGame (k a) r' Nothing - Nothing and my GameMonad instance: instance GameMonad Game where extraLife= Game $ \l - Just ((),l+1) getLives = Game $ \l - Just (l,l) die = do n - getLives Game $ \_ - Just ((),n-1) -- Here's the problem so, what's bothering me? Look at the type signature of die in the GameMonad class, it's supposed to return something of type (m a), but I don't know what to return in that case, and whatever I try to return it doesn't work, because when I try to compile it says that it couldn't match expected type 'a' against infered type 'whatever' ('whatever' being anything, from (), to string, or a number). shouldn't 'a' match with anything I put there? Note that I can't change the signatures because they were giving to me that way and I already checked with teacher if they were right. (I fixed it returning Maybe (Maybe a, Int) instead, but I can't change the signature of the function runGame) Thanks you, Hector Guilarte ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] does () match with a??
On Wed, Jul 7, 2010 at 8:48 PM, John Meacham j...@repetae.net wrote: Are you sure you are interpreting what 'die' should do properly? Your code makes sense if die should decrement your life counter and continue along, however if 'die' is meant to end your whole game, then there is another implementation that does type check. John You're absolutely right, I sen't the wrong code, here's the correct one and a little bit more explanation about what checkpoint does. The result of die makes sense for the checkPoint function since there are three cases for it: 1) The player died and has no remaining lifes. The game can't continue, I just return Noting in the die function and in checkpoint make the corresponding case. 2) The player died and has remaining lifes. The game can be retried with a life subtracted. I would need to tell checkpoint that I died and I want to retry, that's where I think the result is important, because of the next case. 3) The player didn't died, it finished the particular game and checkpoint m equals m. Here I would need to see if the result of the game was different from the result from die, and continue. instance GameMonad Game where extraLife= Game $ \l - Just ((),l+1) getLives = Game $ \l - Just (l,l) die = do n - getLives if n = 0 then Game $ \_ - Nothing else Game $ \_ - Just (player died,n-1) checkPoint a = do n - getLives case execGame a n of Nothing - Game $ \_ - Nothing Just c - gameOn $ fst c where gameOn player died = a = \_ - (checkPoint a) gameOn _ = a Obviously this fails to compile because I'm returning a String and it doesn't match with a either, but the idea of what I think I need to do is right there. Ivan Miljenovic told me to use error, and actually I though something like that. in STM retry combined with atomically does something similar as what I need checkpoint and die to do, and they use exceptions to accomplish it. I really think that's the solution I want, but then I have another question, when I 'throw' the exception in die and 'catch' it in checkpoint to call it again, is the number of lives gonna be lives - 1? Thanks for answering so quickly, Hector Guilarte Pd: Here's an example run of how my homework should work after is finished printLives :: ( GameMonad m , MonadIO m ) = String - m () printLives = do n - getLives liftIO $ putStrLn $ s ++ ++ show n test1 :: ( GameMonad m , MonadIO m ) = m () test1 = checkPoint $ do printLives Vidas : die liftIO $ putStrLn Ganamos ! lastChance :: GameMonad m = m () lastChance = do n - getLives if n == 1 then return () else die test2 :: ( GameMonad m , MonadIO m ) = m String test2 = checkPoint $ do printLives Inicio n - getLives if n == 1 then do liftIO $ putStrLn Final return Victoria ! else do checkPoint $ do printLives Checkpoint anidado lastChance extraLife printLives Vida extra ! die AND THE OUTPUT TO SOME CALLS ghci runGameT test1 3 Vidas : 3 Vidas : 2 Vidas : 1 Nothing ghci runGameT test2 3 Inicio 3 Checkpoint anidado 3 Checkpoint anidado 2 Checkpoint anidado 1 Vida extra ! 2 Inicio 1 Finish Just ( Victoria ! ,1) -- John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/ ___ 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] How does one get off haskell?
Haven't tried this, but maybe it can help you... Online freelance jobs search engine, I'ts supposed to be good... http://www.donanza.com/ Good Luck $$$, Hector Guilarte Enviado desde mi dispositivo movil BlackBerry. -Original Message- From: Günther Schmidt gue.schm...@web.de Date: Thu, 17 Jun 2010 15:55:15 To: haskell-cafe@haskell.org Subject: [Haskell-cafe] How does one get off haskell? Hi list, I'm facing a really tough problem. About 3 years ago I stopped doing freelance and quite nicely paid projects in Java, PHP and C#. Now I'm dire straits, again, and need to get back into the project market which seems to have picked up again, quite a lot of projects out there and it looks like I could ask again for decent rates. (I personally call them compensation because I never ever enjoyed doing Java etc. but the money was good.) Anyway the problem is that I am totally reluctant to code in anything else but haskell. It has always been a problem to me getting up early in the morning, taking a train to work and coming back in the evening totally exhausted. But I think I could manage that again, at least for 3 or 6 months and then my bank account will be fine again and I can take it easy for another year or so. But this time all this is much harder. I really cannot see myself writing such huge amounts of code over and over again not doing much, well you know the story. BTW this is not meant as a fun post, I'm actually quite serious, ie. I need money, only way of getting it is doing Java, C# or PHP. So how does one get off haskell? Are there people in similar situations that have managed? How did you do it? Günther ___ 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] Computer Graphics and Haskell - Radiosity Methods
Hello cafe, While I was studying for my computer graphics test I have tomorrow I realized that maybe some of the major problems I've read so far about Radiosity Rendering Algorithms may be reduced significantly if it was implemented in Haskell and taking advantage of the lazy evaluation so that only what can be seen from the viewer's perspective point of view is calculated, and the rest of the scene just remains as thunks waiting for them to be calculated in case they are needed. I guess that probably most of the people on this list doesn't really work on the computer graphics area, but if anybody out there actually does I'd really like if he or she could explain me more of why what I'm saying could be really useful and what has already been done (or why I'm so lost that I'm probably gonna fail my exam tomorrow hahaha)... One of the things I'm studying is the Monte Carlo Radiosity Methods which takes advantages of non-determinism to create stochastic algorithms, I guess this is more difficult to implement in Haskell, please if you know any of this Monte Carlo Methods for Radiosity Algorithms share that knowledge with me (and the list). Thank you, Hector Guilarte ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re: [Haskell-cafe] Generating Haskell From a XSD
I'd like to help... I'm not an expert in Haskell, but I guess I could help somehow... Hector Guilarte -Original Message- From: jonathangfisch...@gmail.com Date: Wed, 23 Dec 2009 18:11:21 To: Keith Sheppardkeiths...@gmail.com; jonathangfisch...@gmail.com Cc: haskell-cafe@haskell.org Subject: Re: Re: [Haskell-cafe] Generating Haskell From a XSD ___ 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] Help mixing pure and IO code
One time I needed to do use a random number in some places of a completly pure program so I made a infinite list of random numbers and passed it around all the time in the functions as they where called, using the head of the list I passed to the function whenever I needed a random number and returning a tuple which it's second element was the tail of the random numbers list e.g. f:: [int] - (a,[Int]) f randomList = let usedRandomNumber = g $ head randomList in (usedRandomNumber,(tail randomList)) or even something like: f:: [int] - (a,[Int]) f randomList = let (usedRandomNumber,newRandomList) = g randomList in (usedRandomNumber,newRandomList) where g:: [int] - (a,[Int]) The actuall code for doing this is: (Warning, it uses unsafePerformIO, just for the seed of the random Generator, I really don't think it would do any harm) rand :: (RandomGen g, Random a) = (a,a) - g - [a] rand range gen = as where (a,b) = split gen -- create two separate generators as = randomRs range a -- one infinite list of randoms seed :: Int seed = fromInteger (unsafePerformIO getCPUTime) mygen = mkStdGen seed infinito:: (Num t,Random t) = [t] infinito = [ x | x - rand (1,100) mygen] infinito is the function that you need to call in your code that will give you the infinite list of random numbers which will be evaluated lazyly... Hope you can use this... About the prompt thing, that you'll have to wait for another answer or use what they have already told you, Greetings, Hector Guilarte On Mon, Nov 30, 2009 at 8:13 PM, Eric Dedieu papa.e...@free.fr wrote: Still more importantly to me, I understand that anyhow if I intend to use IO or random numbers, I must design my strategy from the beginning as encapsulated in a monad. Something like: class (Monad m) = Strategy m a where ... That's not true at all, you can always pass this data to your strategy entry points and let haskell get it lazily, though it is not as intuitive as other aproaches, That seems exactly what I had tried to do (and failed) in my original code. The Fixed type was to provide the list of moves: data Fixed = Fixed [Move] deriving Show and instanciate a strategy that ignores the game to make decisions, just return the provided moves, then zeroes if ever exhausted: instance Strategy Fixed where proposeNext game s = case s of Fixed [] - (0, Fixed []) Fixed (x:xs) - (x, Fixed xs) but when using an IO Fixed, the questions were not repeated lazily as needed, as if the list of moves was entirely evaluated; so this failed: askUntil :: String - IO Fixed askUntil name = liftM Fixed (sequence $ repeat askio) where askio = putStr (name ++ , pick a number: ) readLn I thought that sequencing [IO Move] to IO [Move] was what breaked lazyness, so I tried other ways to turn an [IO Move] into a IO Strategy, and failed. If I did not interpret correctly why this was not lazy, or if it is indeed possible to do otherwise can you please show me how? Thanks, Eric ___ 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] Machine Learning Library (SVM)
Hello cafe, Does anybody knows if there is a Machine Learning Library for Haskell? I looked in hackage and couldn't find anything but something for Data Mining but that's not what I need, however, googling I saw a ticket for google summer of code for writing such library proposed by Ketil Malde. Ketil, has any progress been made on that library? Specially in the SVM part which is what I'm really looking for... Thanks to everyone in advance, Hector Guilarte ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] AND/OR Perceptron
Hi cafe, I'm trying to implement a Perceptron in Haskell and I found one in: http://jpmoresmau.blogspot.com/2007/05/perceptron-in-haskell.html (Thanks JP Moresmau) but there is one line I don't understand, I was wondering if someone could explain it to me. I know the theory behind a perceptron, my question is more about the Haskell syntax in that line I don't understand. epoch :: [([Float],Float)] - -- ^ Test Cases and Expected Values for each test case [Float] - -- ^ weights ([Float],Float) -- ^ New weights, delta epoch allInputs weights= let f w (inputs,expected) = step inputs w expected -- I don't understand this line newWeights = foldl f weights allInputs -- Neither this one delta = (foldl (+) 0 (map abs (zipWith (-) newWeights weights))) / (fromIntegral $ length weights) in (newWeights,delta) What is f and what is w? I really don't get it, Is like it is defining a function f which calls step unziping the input, taking one of the elements from the fst and it's corresponding snd and invoking step with that, along with w (which seems to be a list according to step's signature but I don't know where it comes from), and then applying fold to the weights and all the Inputs using that f function... But I don't get it! Maybe if someone could rewrite that redefining f as an separate function and calling fold with that function I'll get it. The input for epoch would be something like this: epoch [([0,0],0),([0,1],0),([1,0],0),([1,1],1)] [-0,413,0.135] and the output for that examples is: ([0.0,412.9],3.333537e-2) Thanks a lot, Hector Guilarte ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] AND/OR Perceptron
Thanks Tim! I got it! I have never declared a function before in a let ... in statement, I always do it in a where after I call it... On Fri, Oct 30, 2009 at 3:03 PM, Tim Wawrzynczak inforichl...@gmail.comwrote: Hector, That line is declaring a function named 'f' of two arguments: one is 'w', and the other is a tuple. The tuple's fst is 'inputs', and its snd is 'expected.' This function (f) is used in the next line, in the declaration of the list 'newWeights,' which uses f as the function which does the fold over the allInputs list. Cheers, - Tim On Thu, Oct 29, 2009 at 2:27 PM, Hector Guilarte hector...@gmail.comwrote: Hi cafe, I'm trying to implement a Perceptron in Haskell and I found one in: http://jpmoresmau.blogspot.com/2007/05/perceptron-in-haskell.html (Thanks JP Moresmau) but there is one line I don't understand, I was wondering if someone could explain it to me. I know the theory behind a perceptron, my question is more about the Haskell syntax in that line I don't understand. epoch :: [([Float],Float)] - -- ^ Test Cases and Expected Values for each test case [Float] - -- ^ weights ([Float],Float) -- ^ New weights, delta epoch allInputs weights= let f w (inputs,expected) = step inputs w expected -- I don't understand this line newWeights = foldl f weights allInputs -- Neither this one delta = (foldl (+) 0 (map abs (zipWith (-) newWeights weights))) / (fromIntegral $ length weights) in (newWeights,delta) What is f and what is w? I really don't get it, Is like it is defining a function f which calls step unziping the input, taking one of the elements from the fst and it's corresponding snd and invoking step with that, along with w (which seems to be a list according to step's signature but I don't know where it comes from), and then applying fold to the weights and all the Inputs using that f function... But I don't get it! Maybe if someone could rewrite that redefining f as an separate function and calling fold with that function I'll get it. The input for epoch would be something like this: epoch [([0,0],0),([0,1],0),([1,0],0),([1,1],1)] [-0,413,0.135] and the output for that examples is: ([0.0,412.9],3.333537e-2) Thanks a lot, Hector Guilarte ___ 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] double colon equal
That expression below Is a part of a Grammar in BNF. It means that an expression is form by an expression, an add operation and a Term or simply just a Term... -Original Message- From: xu zhang douy...@gmail.com Date: Tue, 29 Sep 2009 14:15:48 To: haskell-cafe@haskell.org Subject: [Haskell-cafe] double colon equal ___ 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] SLD resolution code in Haskell
Hey Steffen, I actually made it one time, remember me to send it to you on monday... Hector Guilarte -Original Message- From: Steffen Bock bock.stef...@yahoo.de Date: Fri, 28 Aug 2009 23:03:24 To: Haskell-Cafe@haskell.org Subject: [Haskell-cafe] SLD resolution code in Haskell ___ 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] Implementing Las Vegas algorithms in Haskell
A few days ago I had to randomly choose and element of a list and continue execution, so here's what I did: I made a infinite list of Random numbers [Int] (Not IO [Int]) and I passed it around all the time in a Tuple and whenever I returned I also returned the list, so I would always have it available whenever I needed to use it. Whenever I used it I took it's head off and returned the tail, along with whatever else I was returning in a Tuple. The seed for the Random Generator was the CPUTime. Here's the code: (The function that returns the infinite list is infinito, the one on the bottom) import Random import CPUTime import System.IO.Unsafe {-| La funcion @rand@ Retorna una lista de numeros Random para ser utilizados en la seleccion de las guardias en los if y los do -} rand :: (RandomGen g, Random a) = (a,a) - g - [a] rand range gen = as where (a,b) = split gen -- create two separate generators as = randomRs range a -- one infinite list of randoms {-| @seed@ Retorna la semilla con la que la funcion Random va a iniciar la generacion de los numeros Randoms -} seed :: Int seed = fromInteger (unsafePerformIO getCPUTime) {-| @mygen@ Retorna el generador estandar con la semilla dada por la funcion @seed@ -} mygen = mkStdGen seed {-| @infinito@ Retorna la lista infinita de donde se van a sacar los numeros para elegir la guardia a ser ejecutada en los if y los do -} infinito:: (Num t,Random t) = [t] infinito = [ x | x - rand (1,100) mygen] Hope it works for you! Hector Guilarte ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] A Strict GCL Interpreter in Haskell
Hi everyone! (First of all, I don't know Monads!) I made a GCL (Guarded Command Language) Compiler and Interpreter for my Languages and Machines course in my University with alex, happy and ghc. I still have a doubt: 1) Since Haskell is Lazy, and my GCL program is being interpreted in Haskell then my GCL is Lazy too (I know is not as simple as that but believe me, somehow it is behaving lazy). The problem is that it can't be lazy (said to me by my teacher on monday) so I tried using seq, but it didn't work, I'll paste the code after this: Programs in GCL like: a) var i : value main i - 1 / 0 end b) var i : value main i - 1 / 0; show i end c) var i : value var foo : array of 2 main i - foo[42] end d) var i : value var foo : array of 2 main i - foo[42]; show i end act like this: a and c finish interpretation b throws division by zero error and finish interpretation d throws index out of bounds error and finish interpretation Now the code: (it is in Spanish. ListLValue is a List of L-Values for the assigments, ListExpr is the list of Expressions to be assigned, Tabla is the Symbol Table (Data.Map), actualizarVar updates a Variable in the Symbol Table with the new value valor, ActualizarArray updates the position indice of an array in the Symbol Table. evalExpr evaluates an arithmetic Expression and returns an Int. Inside evalExpr are the verifications for division by zero of modulo by zero.) evalAsignacion:: ListLvalue - ListExpr - Tabla - Tabla evalAsignacion [] [] tabla = tabla evalAsignacion ((Lid id):valueList) (expr:exprList) tabla = let valor = (evalExpr expr tabla) in valor `seq` evalAsignacion valueList exprList (actualizarVar id valor tabla) evalAsignacion ((LArrayPosition id exprArray):valueList) (expr:exprList) tabla = let valor = (evalExpr expr tabla) indice = (evalExpr exprArray tabla) in valor `seq` indice `seq` evalAsignacion valueList exprList (actualizarArray id indice valor tabla) evalExpr:: Expr - Tabla - Int evalExpr expr tabla = let salida = (snd (evalAritmetico expr tabla)) in salida `seq` if (isLeft salida) then error (getLeft salida) else getRight salida --((Int,Int) is the Line and Colum, that's for error reporting) evalAritmetico :: Expr - Tabla - ((Int,Int),(Either String Int)) --LET ME KNOW IF YOU NEED THIS PART TOO Thanks in advance, Hector Guilarte ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Making a strict (non-lazy) GCL Interpreter
Thanks Ketil, I'll try to give that a try, but as I said beforen, I don't know anything about monads, and since this project is for next monday and I have many other projects for the University for next week too I can't learn them right now... What I need to do is randomly select an element from a List... Any Ideas? Also, I had another question in my original e-mail... Any ideas about that? --Original Message-- From: Ketil Malde To: Hector Guilarte Cc: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Making a strict (non-lazy) GCL Interpreter Sent: Jun 30, 2009 05:00 Hector Guilarte hector...@gmail.com writes: I need to randomly select ONE of the valid conditions and execute it's instruction. I know there is a Random Monad, but it returns an IO Int, No, this is not right. Values in the Random monad are computations that rely on randomness, but they can produce values of arbitrary type. (The 'a' in 'Random a', no?) Is there anyway I can do some Random that doesn't involve IO? or any other solution? Some options are: 1. Use the IO monad 2. Use the Random monad 3. Pass around a RandomGen explicitly 4. Generate an infinite stream of random values, and pass that around I think option 2 is the nicest, but option 4 may work if the use of randomness is limited. No. 3 does the same as 2 (I presume, I never looked) but with a lot more noise in your code, and no. 1 erases the separation between real IO, and computations -- which IME includes a lot of them -- that happen to depend on randomness (but require no other IO). -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Making a strict (non-lazy) GCL Interpreter
Hi everyone! (First of all, I don't know Monads!) I made a GCL (Guarded Command Language) Compiler and Interpreter for my Languages and Machines course in my University with alex, happy and ghc. I asked about a week ago about the use of unsafePerformIO for that same project, now I have two new doubts: 1) When more than a Condition is true in a if cond1 - instruction1 | cond2 - instruction2 ... | condN - instructionN fi I need to randomly select ONE of the valid conditions and execute it's instruction. I know there is a Random Monad, but it returns an IO Int, Is there anyway I can do some Random that doesn't involve IO? or any other solution? That part of the code is: (My code is in Spanish. TablaOutput is a type and it stands for the tupe of the Symbol Table (Data.Map) and the Output [String], obtenerValidos checks wich pair of (condition,instruction) are true and makes a list out of them, ejecutarUnoRand is the Instruction that executes one of the instructions randomly) evalSeleccion:: [(BoolY,Instruccion)] - TablaOutput - TablaOutput evalSeleccion lista tabla = let validos = obtenerValidos lista [] tabla in if (isEmpty validos) then error Las guardias del If estan incompletas else ejecutarUnoRand validos tabla obtenerValidos:: [(BoolY,Instruccion)] - [(BoolY,Instruccion)] - TablaOutput - [(BoolY,Instruccion)] obtenerValidos [] validos tabla = validos obtenerValidos ((boolY,instruccion):bloqueIns) validos tabla = if (evalBoolY boolY (fst tabla)) then obtenerValidos bloqueIns (validos ++ [(boolY,instruccion)]) tabla else obtenerValidos bloqueIns validos tabla ejecutarUnoRand:: [(BoolY,Instruccion)] - TablaOutput - TablaOutput ejecutarUnoRand validos tabla = let rand = 0 --getStdRandom (randomR (0,(length validos))) HERE'S WHERE I'M SUPPOSED TO DO RANDOM, RIGHT NOW I'M JUST CHOSING THE FIRST in evalInstruccion (snd (validos !! rand)) tabla 2) Since Haskell is Lazy, and my GCL program is being interpreted in Haskell then my GCL is Lazy too (I know is not as simple as that but believe me, somehow it is behaving lazy). The problem is that it can't be lazy (said to me by my teacher today) so I tried using seq, I'll paste the code after this: Programs in GCL like: a) var i : value main i - 1 / 0 end b) var i : value main i - 1 / 0; show i end c) var i : value var foo : array of 2 main i - foo[42] end d) var i : value main i - foo[42]; show i end acts like this: a and c finish interpretation b throws division by zero error and finish interpretation d throws index out of bounds error and finish interpretation Now the code: (again, it is in Spanish. ListLValue is a List of L-Values for the assigments, ListExpr is the list of Expressions to be assigned, Tabla is the Symbol Table (Data.Map), actualizarVar updates a Variable in the Symbol Table with the new value valor, ActualizarArray updates the position indice of an array in the Symbol Table. evalExpr evaluates an arithmetic Expression and returns an Int. Inside evalExpr are the verifications for division by zero of modulo by zero.) evalAsignacion:: ListLvalue - ListExpr - Tabla - Tabla evalAsignacion [] [] tabla = tabla evalAsignacion ((Lid id):valueList) (expr:exprList) tabla = let valor = (evalExpr expr tabla) in valor `seq` evalAsignacion valueList exprList (actualizarVar id valor tabla) evalAsignacion ((LArrayPosition id exprArray):valueList) (expr:exprList) tabla = let valor = (evalExpr expr tabla) indice = (evalExpr exprArray tabla) in valor `seq` indice `seq` evalAsignacion valueList exprList (actualizarArray id indice valor tabla) evalExpr:: Expr - Tabla - Int evalExpr expr tabla = let salida = (snd (evalAritmetico expr tabla)) in salida `seq` if (isLeft salida) then error (getLeft salida) else getRight salida --((Int,Int) is the Line and Colum, that's for error reporting) evalAritmetico :: Expr - Tabla - ((Int,Int),(Either String Int)) --LET ME KNOW IF YOU NEED THIS PART TOO Thanks in advance, Hector Guilarte ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Using unsafePerformIO safely
Hello, I made a GCL compiler using Alex and Happy and now I'm making the interpreter to that program. Here's the deal: First of all, I'm no expert in the usage of monads. Now: Whenever a show instruction is found in any GCL program while the interpretation is being done it is supposed to print on the stdout the string or the aritmetic expresion it was called with, so I guessed I need to run an IO operation and continue the interpretation of my program. I managed to do this using unsafePerformIO and `seq` like is shown below. My question is: Is it safe to use it this way? So far it is working great, but I need to be sure I'm using it in a safe way. Like I said, I'm no expert in monads and the System.IO.Unsafe documentation says: *unsafePerformIO* :: IOhttp://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#t%3AIOa - a This is the back door into the IOhttp://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#t%3AIOmonad, allowing IOhttp://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#t%3AIOcomputation to be performed at any time. For this to be safe, the IOhttp://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#t%3AIOcomputation should be free of side effects and independent of its environment. I don't know if the IO computation I'm doing is free of side effects and independent of its enviroment :s. (is just hPutStr stdout ) Also I've read something about my code not being executed for sure or something like that. Can somebody check the code and tell me if I'm safe with it? Thanks a lot! Here's the code: -- Tabla is my Symbol Table of the program being interpreted evalInstruccion:: Instruccion - Tabla - Tabla evalInstruccion (ShowY showY) tabla = myRunIO (evalShow showY tabla) evalInstruccion _ tabla = tabla -- There are many other Instructions here missing wich are not relevant to my question {-# NOINLINE myRunIO #-} myRunIO:: (Tabla, IO()) - Tabla myRunIO tupla = ((unsafePerformIO (snd tupla)) `seq` (fst tupla)) -- Here's the unsafePerformIO Am I safe? evalShow:: ShowY - Tabla - (Tabla, IO()) evalShow (ShowS string) tabla = (tabla,(hPutStr stdout string)) evalShow (ShowE expr) tabla = (tabla,(hPutStr stdout (show (evalExpr expr tabla -- Don't worry about evalExpr, it works and returns an Int ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Using unsafePerformIO safely
Thanks for answering so fast. Yes, GCL == Guarded Command Language... It is for an assigment I have in my Languages and Machines Course. About the nicer/Haskellier solution you proposed: If there is a way of printing right in the moment the Interpreter finds the show instruction then I don't think the teacher is gonna like this soluttion (I would bet on that) so, can you (or somebody) explain a little bit better how would the ugly solution be? As I said earlier, I'm no expert in monads, actually the truth is that I know almost nothing about monads, so please, explain it to me as if you are explaining it to a Monads newbie... Also, can somebody explain me how would it be using the Writer Monad? remember is for a Monads newbie... Thanks a lot! Hector Guilarte On Thu, Jun 25, 2009 at 6:04 PM, Jochem Berndsen joc...@functor.nl wrote: Hector Guilarte wrote: I made a GCL compiler using Alex and Happy and now I'm making the interpreter to that program. Here's the deal: First of all, I'm no expert in the usage of monads. Now: Whenever a show instruction is found in any GCL program while the interpretation is being done it is supposed to print on the stdout the string or the aritmetic expresion it was called with, so I guessed I need to run an IO operation and continue the interpretation of my program. I managed to do this using unsafePerformIO and `seq` like is shown below. My question is: Is it safe to use it this way? So far it is working great, but I need to be sure I'm using it in a safe way. Like I said, I'm no expert in monads and the System.IO.Unsafe documentation says: *unsafePerformIO* :: IO http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#t%3AIO a - a This is the back door into the IO http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#t%3AIO monad, allowing IO http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#t%3AIO computation to be performed at any time. For this to be safe, the IO http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#t%3AIO computation should be free of side effects and independent of its environment. I don't know if the IO computation I'm doing is free of side effects and independent of its enviroment :s. (is just hPutStr stdout ) Well, writing to the standard output is certainly a side effect. (This does not mean that you cannot use unsafePerformIO. The compiler, however, may assume that any value is free from side effects. This means that you could get, in theory, less or more output from your program than you want. In this sense it is not safe.) Also I've read something about my code not being executed for sure or something like that. Can somebody check the code and tell me if I'm safe with it? It's safe in the sense that it probably won't blow up your computer. It may also work. On the other hand, I would not recommend using unsafePerformIO in this way. I see two possibilities for resolving this issue: * (ugly) run your GCL (Guarded Command Language?) interpreter in the IO monad, and using print/putStr/... whenever you encounter a 'show' statement in the GCL program. * (nicer/Haskellier) adapt your interpreter such that it returns a list of Strings to output. You have then a purely functional interpreter, and in the main function of your program you can print this list. This will be lazily evaluated as the GCL program runs. You now have a very nice separation of clean, pure code, and impure code in the IO monad (your main function, which can be pretty small in your case). To avoid boilerplate, you can use the Writer monad, for example, but others may have better suggestions. Kind regards, -- Jochem Berndsen | joc...@functor.nl GPG: 0xE6FABFAB ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Using unsafePerformIO safely
On Thu, Jun 25, 2009 at 11:35 PM, Luke Palmer lrpal...@gmail.com wrote: On Wed, Jun 24, 2009 at 7:56 PM, Hector Guilarte hector...@gmail.comwrote: Thanks for answering so fast. Yes, GCL == Guarded Command Language... It is for an assigment I have in my Languages and Machines Course. About the nicer/Haskellier solution you proposed: If there is a way of printing right in the moment the Interpreter finds the show instruction then I don't think the teacher is gonna like this soluttion (I would bet on that) so, can you (or somebody) explain a little bit better how would the ugly solution be? As I said earlier, I'm no expert in monads, actually the truth is that I know almost nothing about monads, so please, explain it to me as if you are explaining it to a Monads newbie... The ugly solution is essentially to write it as an imperative program. IO monad is a fancy word for imperative programming. I'm beginning to think the best way to teach monads is not to (until the student is essentially begging for them without knowing it), and let them be grown into as the pattern is seen. So, let's not use them. Let's give the language a semantics of the form Tabla - ([String], Tabla). That means that every expression has the meaning of a function which takes a symbol table, and outputs a series of lines and a new symbol table. This will be the range of your evalInstruccion. I'll do the ShowY case and a Sequence case for sequencing together multiple instructions, which is important. The rest should be straightforward from there. evalInstruccion :: Instruccion - Tabla - ([String], Tabla) evalInstruccion (ShowY showY) tabla = ([evalShow showY tabla], tabla) evalInstruccion (Sequence instr1 instr2) tabla = let (out1, tabla') = evalInstruccion instr1 tabla (out2, tabla'') = evalInstruccion instr2 tabla' in (out1 ++ out2, tabla'') ... evalShow :: ShowY - Tabla - String evalShow = ... This pattern can be used for more than lists of strings; it can be used for any monoid. If I were to follow the pattern of your code, the monoid would be IO (), and the operation (instead of (++)) would be (). But there would still be no unsafePerformIO, the semantics of the langauge would be Tabla - (IO (), Tabla), and we would put build one big IO () to return at the end from the output of the subexpressions. Does this make sense? Luke Hi Luke, Thanks! Actually, if I understood well what you proposed, that's how I first tought of doing it, but with a [Maybe String] and only append whenever I actually had a (Just string), but as I said before, I don't think my teacher is gonna like that solution since it is not going to print when the interpreter finds the show instruction in the GCL code, it is gonna wait until it finishes to interpret the whole code and then print everything. That's would be ok with me, but actually in a language point of view that wouldn't be to usefull, since trying to debug a program printing flags couldn't be done (and I'm not doing a debbuger for it). I know my language is not gonna be used for real, but I'm sure that would be my teacher's argument to tell me I can't do it that way. Still, I sent him an e-mail asking if it can be done like that just in case. If I didn't understand what you said, can you explain it again please? If I did then, does anybody knows how to print on the screen in the moment the show instruction is interpreted that guarantees that my code is gonna be safe Also, nobody has told me why I shouldn't just use my original solution using unsafePerformIO, is it really bad? is it dangerous? why is it unsafe? once again thanks a lot in advance, Hector Guilarte Also, can somebody explain me how would it be using the Writer Monad? remember is for a Monads newbie... Thanks a lot! Hector Guilarte On Thu, Jun 25, 2009 at 6:04 PM, Jochem Berndsen joc...@functor.nlwrote: Hector Guilarte wrote: I made a GCL compiler using Alex and Happy and now I'm making the interpreter to that program. Here's the deal: First of all, I'm no expert in the usage of monads. Now: Whenever a show instruction is found in any GCL program while the interpretation is being done it is supposed to print on the stdout the string or the aritmetic expresion it was called with, so I guessed I need to run an IO operation and continue the interpretation of my program. I managed to do this using unsafePerformIO and `seq` like is shown below. My question is: Is it safe to use it this way? So far it is working great, but I need to be sure I'm using it in a safe way. Like I said, I'm no expert in monads and the System.IO.Unsafe documentation says: *unsafePerformIO* :: IO http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#t%3AIO a - a This is the back door into the IO http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#t%3AIO monad, allowing IO
Re: [Haskell-cafe] Using unsafePerformIO safely
On Fri, Jun 26, 2009 at 12:58 AM, Brandon S. Allbery KF8NH allb...@ece.cmu.edu wrote: On Jun 26, 2009, at 00:43 , Hector Guilarte wrote: Thanks! Actually, if I understood well what you proposed, that's how I first tought of doing it, but with a [Maybe String] and only append whenever I actually had a (Just string), but as I said before, I don't think my teacher is gonna like that solution since it is not going to print when the interpreter finds the show instruction in the GCL code, it is gonna wait until it finishes I think maybe you don't quite have a grasp of lazy evaluation yet. Try it. Also, nobody has told me why I shouldn't just use my original solution using unsafePerformIO, is it really bad? is it dangerous? why is it unsafe? You were told earlier: Well, writing to the standard output is certainly a side effect. (This does not mean that you cannot use unsafePerformIO. The compiler, however, may assume that any value is free from side effects. This means that you could get, in theory, less or more output from your program than you want. In this sense it is not safe.) Because pure (i.e. non-IO) values by definition never change, the compiler is free to assume that it can do them exactly once and remember the result. This means that it is possible for the compiler to evaluate your unsafePerformIO once and never again... or, more likely, to notice that the pure result is always () (because unsafePerformIO hides the IO from the compiler) and optimize it away completely (the do it exactly once being at compile time instead of run time). Ok, I got it this time, thanks! I should really talk this with my teacher. I'll post whatever he tells me... Let's hope he lets me just acumulate all the strings and print them in the end. Thanks again! Hector Guilarte ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe