Re: [Haskell-cafe] Unwrapping long lines in text files

2010-08-14 Thread Ronald Guida
On Sat, Aug 14, 2010 at 12:33 PM, Bill Atkins watk...@alum.rpi.edu wrote: Try this one (http://gist.github.com/524460) I noticed that Bill's solution doesn't seem to work if the input text is infinite. I found a different solution, which avoids the use of reverse, and will work even if the

[Haskell-cafe] Weird behavior with arrow commands

2010-07-23 Thread Ronald Guida
I am trying to figure out how to use GHC's arrow commands, and I found some extremely weird behavior. In GHC's manual, there is a description of arrow commands, which I don't really understand. http://www.haskell.org/ghc/docs/latest/html/users_guide/arrow-notation.html#id667303 (Primitive

[Haskell-cafe] Randomized N-Queens

2010-03-26 Thread Ronald Guida
Hi, I'm trying to solve the N-queens problem, but with a catch: I want to generate solutions in a random order. I know how to solve the N-queens problem; my solver (below) generates all possible solutions. What I am trying to do is generate solutions in a random order by somehow randomizing the

Re: [Haskell-cafe] Graphical representation of Haskell code

2010-03-24 Thread Ronald Guida
Those are some very interesting visual languages, Miguel! I remember drawing some diagrams when I was teaching myself Haskell, but I never actually tried to create a formal visual language. Since my background is in hardware engineering, I would naturally gravitate toward schematic diagrams. I

Re: [Haskell-cafe] Graphical representation of Haskell code

2010-03-24 Thread Ronald Guida
On Wed, Mar 24, 2010 at 9:47 PM, Richard O'Keefe o...@cs.otago.ac.nz wrote: On Mar 25, 2010, at 2:33 PM, Ronald Guida wrote: ... a version of map as text ... ... a diagram ... The thing that strikes me forcibly is that the diagram is much bigger than the text. Not only that, but if I am

Re: [Haskell-cafe] Graphical representation of Haskell code

2010-03-22 Thread Ronald Guida
On Mon, Mar 22, 2010 at 7:02 PM, Dupont Corentin corentin.dup...@gmail.com wrote: Hello, I’m relatively new to Haskell. I’m wondering if it exist a tool to graphically represent Haskell code. ... Let’s try to do it on a simple example, as an exercise: f = Map (+1) Your graphic for f = map

Re: [Haskell-cafe] Newbie: Replacing substring?

2008-07-22 Thread Ronald Guida
2008/7/22 Dmitri O.Kondratiev [EMAIL PROTECTED]: On the side: The more I use Haskell - the more I like it ! It helps me think about the problem I solve much more clearly then when I use imperative language. If I want to replace a substring in a string, then I would search my string left to

Re: [Haskell-cafe] Existential quantification problem

2008-07-10 Thread Ronald Guida
On Thu, 10 July 2008, Marco Túlio Gontijo e Silva wrote: how do I unbox a existential quantificated data type? Dan Doel wrote: elim :: L a - (forall l. l a - r) - r elim (L e) f = f e Just one catch: You can't actually write a function 'f' of type (forall l. l a - r) without knowing

Re: [Haskell-cafe] Inductive graphs memory usage

2008-07-10 Thread Ronald Guida
On Thu, Jul 10, 2008 at 4:57 PM, Andre Nathan [EMAIL PROTECTED] wrote: Hello I'm trying to create a directed graph using the Data.Graph.Inductive. The graph is a random graph using the G(n, p) model, that is, each of the n nodes is linked to every other node with probability p. So the

[Haskell-cafe] Lazy IO

2008-07-09 Thread Ronald Guida
Suppose I have a lazy function f :: [Int] - [Int], and I happen to know that for all n, the n-th element of the output may only depend on the first (n-1) elements of the input. I want to print a number from f's output list, and then ask the user for the next number in f's input list, and then

[Haskell-cafe] Bug in Emacs Haskell Mode

2008-06-24 Thread Ronald Guida
Emacs Haskell Mode has the following useful feature: when Haskell - Load File is used to load a file into GHCi from Emacs, Haskell Mode automatically looks for a *.cabal file in an attempt to find the project directory. When Haskell Mode finds the *.cabal file, it fails to check whether it has

Re: [Haskell-cafe] Re: Haddock compilation problem

2008-06-20 Thread Ronald Guida
I have added ticket #18 to the Haddock Trac. http://trac.haskell.org/haddock/wiki ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

[Haskell-cafe] Haddock compilation problem

2008-06-19 Thread Ronald Guida
I just upgraded to ghc-6.8.3, using a linux binary, and I am having a problem compiling Haddock. Haddock 2.1.0 and Haddock 2.0.0.0 both fail to build under ghc-6.8.3, but they both build successfully with ghc-6.8.2. I don't know if this is a Haddock problem, or a GHC problem, or perhaps

Re: [Haskell-cafe] Printing a random list

2008-06-08 Thread Ronald Guida
Bryan Catanzaro wrote: However, when I ran my random list generator, the interpreter had a stack overflow. Here's my code again: --- module Main where import IO import Random randomList :: Random a = a - a- [IO a] randomList lbound ubound = randomRIO(lbound,

[Haskell-cafe] Teaching Monads

2008-06-07 Thread Ronald Guida
Monads in Haskell are a topic that I, like most beginners, find difficult and mind-twisting. Now that I think I understand monads, they seem to be very simple; I've read that this is a common experience. So I wonder, what would it take to help beginners catch on with a minimum of fuss or

Re: [Haskell-cafe] Re: appending an element to a list

2008-06-03 Thread Ronald Guida
Thank you, apfelmus. That was a wonderful explanation; the debit method in [1] finally makes sense. [1]: Chris Okasaki. Purely Function Data Structures. http://www.cs.cmu.edu/~rwh/theses/okasaki.pdf ___ Haskell-Cafe mailing list

[Haskell-cafe] Laziness leaks

2008-06-03 Thread Ronald Guida
I was looking at the real time queues in [1] and I wanted to see what would happen if I tried to write one in Haskell. The easy part was translating the real time queue from [1], p43 into Haskell. The hard part is testing to see if the rotations really happen what they should. Basically, I

Re: [Haskell-cafe] Laziness leaks

2008-06-03 Thread Ronald Guida
Don Stewart wrote: 2. Is there any way to systematically search for or detect laziness leaks? Profiling, and looking at the Core. Being explicit about the evaluation strategy you want is a fine idea though. Albert Y. C. Lai wrote A true cause of laziness is in accumulating a chain of

Re: [Haskell-cafe] A simple beginner question

2008-06-03 Thread Ronald Guida
Adam Smyczek wrote: data SampleType = A | B Int | C String | D -- etc. sampleTypes = [A, B 5, C test] :: [SampleType] How do I find for example element A in the sampleTypes list? Here's one way to do it: filter (\x - case x of A - True; otherwise - False) sampleTypes == [A] filter

[Haskell-cafe] Images and GUIs in Haskell

2008-05-31 Thread Ronald Guida
Two questions: 1. In a Haskell program, if all I want to do is output an image, like a graph or chart, what is the simplest library to use? N.B. Simpler := easier to get minimal functionality. I really don't want to wade through a bunch of boilerplate or climb a steep learning curve just to be

Re: [Haskell-cafe] Re: Images and GUIs in Haskell

2008-05-31 Thread Ronald Guida
I wrote: 1. In a Haskell program, if all I want to do is output an image, like a graph or chart, what is the simplest library to use? Achim Schneider wrote: http://hackage.haskell.org/packages/archive/pkg-list.html#cat:Graphics OK, Chart (the first package under Graphics) is obviously the

Re: [Haskell-cafe] runInteractiveCommand: program ends before writing or reading all the output

2008-05-15 Thread Ronald Guida
It looks like a simple race condition to me. You are using waitForProcess pid to wait for runInteractiveCommand to finish, but you don't seem to have anything that waits for createDefFile to finish. main :: IO () main = do (file:_) - getArgs (_, out, _, pid) - runInteractiveCommand $

Re: [Haskell-cafe] Commutative monads vs Applicative functors

2008-05-14 Thread Ronald Guida
David Menendez wrote: To summarize: some applicative functors are commutative, some applicative functors are monads, and the ones that are both are commutative monads. OK, so commutativity is orthogonal to idiom vs monad. Commutativity depends on whether or not the order of side effects is

[Haskell-cafe] Monad vs ArrowChoice

2008-05-14 Thread Ronald Guida
I have read that Monad is stronger than Idiom because Monad lets me use the results of a computation to choose between the side effects of alternative future computations, while Idiom does not have this feature. Arrow does not have this feature either. ArrowChoice has the feature that the sum

[Haskell-cafe] Commutative monads vs Applicative functors

2008-05-13 Thread Ronald Guida
I have a few questions about commutative monads and applicative functors. From what I have read about applicative functors, they are weaker than monads because with a monad, I can use the results of a computation to select between alternative future computations and their side effects, whereas

Re: [Haskell-cafe] Hangman game

2008-01-21 Thread Ronald Guida
Thank you for the positive responses. The best kind of feedback is the kind that makes me have to think, and I've done alot of thinking. _Regarding monads and interfaces_ Paul Johnson wrote: 1: Your GameState type can itself be made into a monad. Take a look at the All About Monads tutorial,

[Haskell-cafe] Smart Constructor Puzzle

2007-12-20 Thread Ronald Guida
I'm playing around with smart constructors, and I have encountered a weird puzzle. My goal is to do vector arithmetic. I'm using smart constructors so that I can store a vector as a list and use the type system to staticly enforce the length of a vector. So my first step is to define Peano

[Haskell-cafe] Space and time leaks

2007-10-03 Thread Ronald Guida
I need some help with space and time leaks. I know of two types of space leak. The first type of leak occurs when a function uses unnecessary stack or heap space. GHCi sum [1..10^6] *** Exception: stack overflow Apparently, the default definition for sum has a space leak. I can define my own

Re: [Haskell-cafe] what is f=f (not) doing ?

2007-09-23 Thread Ronald Guida
Peter Verswyvelen wrote: I though it was impossible to detect a deadlock (and a black hole is something like a deadlock no?) *before* it occurred, but in this case, we're talking about detecting it *when* it occurs, no? And then raising an error instead of just blocking? Generally, it's not

Re: [Haskell-cafe] Win32 Open GL / Glut Applications

2007-09-23 Thread Ronald Guida
Sven Panne wrote: On Friday 21 September 2007 20:19, Ronald Guida wrote: John Wicket wrote: yea, that is probably what I need. Can you post in a step-by-step way. Here is a set of instructions for what I had to do to get FreeGLUT working with GHCi [...]. Oh dear, a long a sad story

Re: [Haskell-cafe] what is f=f (not) doing ?

2007-09-23 Thread Ronald Guida
Miguel Mitrofanov wrote: A deadlock happens whenever two (or more) threads are blocked on each other. Deadlocks can be extremely hard to detect, especially if they occur intermittently. Isn't that so much different from garbage collection? Replace thread with chunk of data, and waits for

Re: [Haskell-cafe] Win32 Open GL / Glut Applications

2007-09-21 Thread Ronald Guida
John Wicket wrote: yea, that is probably what I need. Can you post in a step-by-step way. Here is a set of instructions for what I had to do to get FreeGLUT working with GHCi. RANT Just a little warning: my instructions could be wrong in some places. Normally, in order to verify my

Re: [Haskell-cafe] Win32 Open GL / Glut Applications

2007-09-21 Thread Ronald Guida
Oops, one slight omission: 4. Download this custom makefile and put in in the ./src directory. http://hpaste.org/2841 ** Call this file Makefile, with no extension. 5. Download this custom def file and put in in the ./src directory. http://hpaste.org/2842 ** Call this file

Re: [Haskell-cafe] Win32 Open GL / Glut Applications

2007-09-20 Thread Ronald Guida
John Wicket wrote: I can take any of these opengl applications or other examples on the web, but I can't get the application to run on Win32? They will compile(except for the GLU ones) but when I launch them, the windows just closes? Is HOpenGL supported well on Win32?

Re: [Haskell-cafe] Sequencing Operations in a Monad

2007-09-15 Thread Ronald Guida
SevenThunders wrote: OK so check out what really happens with liftM2. Suppose I have an IO containing an involved matrix computation called s. For simplicity we might assume that s :: IO (Int) and the Int is an index into an array containing a bunch of matrices in C land. Assume

Re: [Haskell-cafe] Sequencing Operations in a Monad

2007-09-14 Thread Ronald Guida
SevenThunders wrote: I have a matrix library written in C and interfaced into Haskell with a lot of additional Haskell support. [snip] Unfortunately if I wrap my matrix references in the IO monad, then at best computations like S = A + B are themselves IO computations and thus whenever they

Re: [Haskell-cafe] Basic FFI with GHC

2007-09-12 Thread Ronald Guida
Ronald Guida wrote: How do I create C-libraries that I can load into GHCi? I am trying to do some basic FFI, and it's not working. So, after more searching on the internet and some RTFM, I think I found my answer, and it seems to work, but I don't know if it's the right answer to generalize

[Haskell-cafe] Basic FFI with GHC

2007-09-11 Thread Ronald Guida
How do I create C-libraries that I can load into GHCi? I am trying to do some basic FFI, and it's not working. Here's the background. I created three files, foo.h, foo.cpp, and test_foo.lhs. (source code below) Note: I am using MinGW/Msys under Windows XP. If I compile foo.cpp and then try

Re: [Haskell-cafe] Can somebody give any advice for beginners?

2007-09-11 Thread Ronald Guida
Dan Piponi wrote: On 9/11/07, Andrew Coppin [EMAIL PROTECTED] wrote: you can fall down a monad and not be able to escape... It's not so bad. It's in the nature of monads that after you've fallen in once, you can never get trapped any deeper. But you can climb higher... (Note: Best viewed in

Re: [Haskell-cafe] Installation of GLUT package

2007-09-09 Thread Ronald Guida
Paul L wrote: But again, why stuck with GLUT? Now there is at least one alternative, GLFW (http://glfw.sourceforge.net) a cross-platform framework for OpenGL applications, for which I recently wrote a Haskell interface, downloadable at http://www.haskell.org/soe/software1.htm. It's certainly

Re: [Haskell-cafe] Serial Communications in Haskell

2007-09-08 Thread Ronald Guida
On 8/28/07, Ronald Guida wrote: I'm on a Windows box and I'm looking for a way to talk to a serial port (for example, RS-232) from Haskell. I couldn't find a library to do this, so I am wondering how to create one. I figured out FFI and marshaling, and I got my serial port to work in Haskell

Re: [Haskell-cafe] Installation of GLUT package

2007-09-08 Thread Ronald Guida
Update: I downloaded MinGW and MSYS and tried to install the GLUT library. I just can't get the thing to work, and I feel like I'm sitting in my own little section of Hell. I have tried everything I could think of so far, and it still doesn't work. Today I tried to sanitize my machine and

Re: [Haskell-cafe] Installation of GLUT package

2007-09-08 Thread Ronald Guida
Paul L wrote: I believe it's caused by the different versions of GLUT you have. On 9/8/07, Ronald Guida [EMAIL PROTECTED] wrote: [...] Loading package OpenGL-2.2.1 ... linking ... done. Loading package GLUT-2.1.1 ... linking ... done. The above message was after you have installed GLUT

[Haskell-cafe] Serial Communications in Haskell

2007-08-28 Thread Ronald Guida
I'm on a Windows box and I'm looking for a way to talk to a serial port (for example, RS-232) from Haskell. I couldn't find a library to do this, so I am wondering how to create one. I have a fairly thorough understanding of how to open and use a serial port with the Windows API. In

Re: [Haskell-cafe] help understanding lazy evaluation

2007-08-23 Thread Ronald Guida
I'm trying to understand lazy evaluation as well. I created an example for myself and I'm wondering if I've got it right. let adder n = \x - n + x in (map (adder 12) [1,2,3]) !! 1 So the first thing I did is draw a graph to represent my expression. (map (adder 12) [1,2,3]) !! 1 =

Re: [Haskell-cafe] Explaining monads

2007-08-13 Thread Ronald Guida
Ronald Guida wrote: Given the question What is a Monad, I would have to say A Monad is a device for sequencing side-effects. peterv [EMAIL PROTECTED] wrote: Side-effects is a piece of linguistic cruft played fast-and-loose by too many people in this game. Sequencing suffers the same disease

Re: [Haskell-cafe] Explaining monads

2007-08-12 Thread Ronald Guida
Stefan O'Rear wrote: On Sat, Aug 11, 2007 at 03:00:04PM -0400, Ronald Guida wrote: The question remains: What is special about Monad or ArrowApply, compared to Arrow? or What is more general about Arrow, compared to Monad or ArrowApply? If all you have is an Arrow, then you must make up

Re: [Haskell-cafe] Explaining monads

2007-08-12 Thread Ronald Guida
Tillmann Rendel wrote: Ronald Guida wrote: Here's a toy language, described by a regular expression: 0(10)*110 I want to read characters, one at a time, and eventually decide to Accept or Reject a string. Let me try to understand my options. * With a simple Arrow, I can create a fixed

Re: [Haskell-cafe] Explaining monads

2007-08-11 Thread Ronald Guida
David Menendez wrote: Be sure to read sigpfe's You could have invented monads! and the Wadler paper. http://sigfpe.blogspot.com/2006/08/you-could-have-invented-monads-and.html http://homepages.inf.ed.ac.uk/wadler/papers/marktoberdorf/baastad.pdf Most tutorials try to explain what a monad

Re: [Haskell-cafe] Explaining monads

2007-08-10 Thread Ronald Guida
Brian Brunswick wrote: g f ??? g ??? f application a a-b flip ($) b monad bind m a a-m b= m b comonad cobind w a w a-b= w b arrowarr a b arr b c arr a c

[Haskell-cafe] Monad for Set?

2007-08-06 Thread Ronald Guida
Hi, I'm pondering, is it possible to define a Set monad analogous to the List monad? My thinking is as follows: * fmap f x would apply f to each element in a set x * return x would create a singleton set {x} * join x, where x is a set of sets: x = {x1, x2, ... xn}, would form

[Haskell-cafe] Installing FreeGLUT

2007-08-01 Thread Ronald Guida
Hi, I am trying to use freeglut with GHCi 6.6.1, and I'm stuck. I downloaded freeglut 2.4.0 and compiled it. I am on a Windows XP machine, and I found that freeglut compiled out of the box in MS Visual Studio.Net 2003. My difficulty is that GHCi is finding GLUT 2.2.1 and not freeglut.

[Haskell-cafe] Hints for Euler Problem 11

2007-07-19 Thread Ronald Guida
Hi, again. I started looking at the Euler problems [1]. I had no trouble with problems 1 through 10, but I'm stuck on problem 11. I am aware that the solutions are available ([2]), but I would rather not look just yet. In Problem 11, a 20x20 grid of numbers is given, and the problem is to

Re: [Haskell-cafe] Lazy Lists and IO - Redux

2007-07-13 Thread Ronald Guida
[Ronald Guida, 07/11/07] Suppose I have a function f that reads a lazy list, such that f only consumes as much of the list as it needs to. Laziness allows me to apply f to an infinite list without creating an infinite loop. Now I want to connect the console to f, such that the list

[Haskell-cafe] Lazy Lists and IO

2007-07-10 Thread Ronald Guida
Hi Everyone, A few weeks ago, I started learning Haskell (and functional programming) on my own from the wealth if information on the internet. I recently read the paper Why Functional Programming Matters [1] and it led me to wonder how to input a lazy list. Suppose I have a function f that