Re: [Haskell-cafe] better way to do this?

2009-10-07 Thread Peter Verswyvelen
--- BEGIN NOSTALGIA --- Well, I have to add to this, that when I coded my first games in assembler in the eighties, I did exactly the same thing: just recording the input of the joystick was enough to get full replays and make auto playing demos. But on the old computers, this was all so easy,

Re: [Haskell-cafe] better way to do this?

2009-10-07 Thread David Virebayre
On Wed, Oct 7, 2009 at 10:05 AM, Peter Verswyvelen bugf...@gmail.com wrote: over every bit of the system (it was even easy to count exactly how many cycles a routine would take :-), so it was just a matter of starting the You sound like you used to code on the Commodore 64 :) David.

Re: [Haskell-cafe] better way to do this?

2009-10-07 Thread Ketil Malde
Peter Verswyvelen bugf...@gmail.com writes: So yes, without using IO, Haskell forces you into this safe spot One could argue that IO should be broken down into a set of sub-monads encapsulating various subsets of the functionality - file system, network access, randomness, and so on. This

Re: [Haskell-cafe] better way to do this?

2009-10-07 Thread Eugene Kirpichov
Or you can use an effect system (however that doesn't give you the opportunity of overriding IO functions, but I think that providing such an opportunity with the means you suggest (splitting IO into many sub-monads) is not going to be usable in the large scale) By the way, I am surprised that

Re: [Haskell-cafe] better way to do this?

2009-10-07 Thread Duncan Coutts
On Tue, 2009-10-06 at 13:22 -0700, Michael P Mossey wrote: Duncan Coutts wrote: So you end up with pure functions like: shuffle :: RandomGen g = g - [x] - [x] Thanks for the help, Duncan. I'm confused on one point. Don't you always need the new state of the generator back? So

Re: [Haskell-cafe] better way to do this?

2009-10-07 Thread Peter Verswyvelen
Yep. Commodore 64, Amiga. I really loved those machined, especially the Amiga (mmm, maybe someone should port a Haskell compiler to the Amiga. ha, how nerdy can one get? ;-) On Wed, Oct 7, 2009 at 10:50 AM, David Virebayre dav.vire+hask...@gmail.comdav.vire%2bhask...@gmail.com wrote: On Wed,

Re: [Haskell-cafe] better way to do this?

2009-10-07 Thread Peter Verswyvelen
On Wed, Oct 7, 2009 at 11:13 AM, Ketil Malde ke...@malde.org wrote: One could argue that IO should be broken down into a set of sub-monads encapsulating various subsets of the functionality - file system, network access, randomness, and so on.  This could extend the safe spot to cover much

Re[2]: [Haskell-cafe] better way to do this?

2009-10-07 Thread Bulat Ziganshin
Hello Peter, Wednesday, October 7, 2009, 2:04:49 PM, you wrote: afair, nhc was started there. it was a small compiler exactly because Amiga was a rather small computer (comapred to RISC stations) Yep. Commodore 64, Amiga. I really loved those machined, especially the Amiga (mmm, maybe someone

Re: Re[2]: [Haskell-cafe] better way to do this?

2009-10-07 Thread Malcolm Wallace
afair, nhc was started there. it was a small compiler exactly because Amiga was a rather small computer (comapred to RISC stations) nhc12 (for Haskell 1.2) was first developed on an Acorn Archimedes with 2Mb of RAM, under RiscOS. Regards, Malcolm

Re: [Haskell-cafe] better way to do this?

2009-10-07 Thread John A. De Goes
On Oct 7, 2009, at 3:13 AM, Ketil Malde wrote: Peter Verswyvelen bugf...@gmail.com writes: So yes, without using IO, Haskell forces you into this safe spot One could argue that IO should be broken down into a set of sub- monads encapsulating various subsets of the functionality - file

Re: [Haskell-cafe] better way to do this?

2009-10-07 Thread John A. De Goes
It's a complex area not a lot of people are working in. Similar (actually worse than) dependent typing. Regards, John A. De Goes N-Brain, Inc. The Evolution of Collaboration http://www.n-brain.net|877-376-2724 x 101 On Oct 7, 2009, at 3:32 AM, Eugene Kirpichov wrote: Or you can

Re: [Haskell-cafe] better way to do this?

2009-10-07 Thread Conor McBride
On 7 Oct 2009, at 15:04, John A. De Goes wrote: On Oct 7, 2009, at 3:13 AM, Ketil Malde wrote: Peter Verswyvelen bugf...@gmail.com writes: So yes, without using IO, Haskell forces you into this safe spot One could argue that IO should be broken down into a set of sub- monads

Re: [Haskell-cafe] better way to do this?

2009-10-07 Thread Edward Z. Yang
Excerpts from Ketil Malde's message of Wed Oct 07 05:13:19 -0400 2009: One could argue that IO should be broken down into a set of sub-monads encapsulating various subsets of the functionality - file system, network access, randomness, and so on. This could extend the safe spot to cover much

Re: [Haskell-cafe] better way to do this?

2009-10-06 Thread Michael P Mossey
Duncan Coutts wrote: So you end up with pure functions like: shuffle :: RandomGen g = g - [x] - [x] Thanks for the help, Duncan. I'm confused on one point. Don't you always need the new state of the generator back? So wouldn't this need to be: shuffle :: RandomGen g = g - [x] - (g,[x])

Re: [Haskell-cafe] better way to do this?

2009-10-06 Thread Felipe Lessa
On Mon, Oct 05, 2009 at 07:24:00AM -0700, Michael Mossey wrote: If I understand correctly, this works because IO is an instance of Applicative, correct? I wonder if any of the random monads are instances of Applicative. If they aren't then that's a bug in the library :). Every monad can be

Re: [Haskell-cafe] better way to do this?

2009-10-06 Thread Michael P Mossey
Michael P Mossey wrote: Also note that I added the Random class constraint to 'shuffle'. I haven't tested this but it might be necessary. Or not? Okay I figured this part out too. The members of the list you are shuffling have no class constraint on them because the 'shuffle' function is not

Re: [Haskell-cafe] better way to do this?

2009-10-05 Thread Michael Mossey
Eugene Kirpichov wrote: [x,y,t,b,l,r] - mapM (getStdRandom . randomR) [(-10,10), (-70,70), ...] return (BoxBounds ...) Thanks. I'm curious about the idea of pattern matching in do-statements that can fail. This particular pattern cannot fail. I read that the fail function was introduced

Re: [Haskell-cafe] better way to do this?

2009-10-05 Thread Michael Mossey
If I understand correctly, this works because IO is an instance of Applicative, correct? I wonder if any of the random monads are instances of Applicative. Felipe Lessa wrote: On Sun, Oct 04, 2009 at 01:55:11PM +0400, Eugene Kirpichov wrote: [x,y,t,b,l,r] - mapM (getStdRandom . randomR)

Re: [Haskell-cafe] better way to do this?

2009-10-05 Thread Eugene Kirpichov
2009/10/5 Michael Mossey m...@alumni.caltech.edu: Eugene Kirpichov wrote: [x,y,t,b,l,r] - mapM (getStdRandom . randomR) [(-10,10), (-70,70), ...] return (BoxBounds ...) Thanks. I'm curious about the idea of pattern matching in do-statements that can fail. This particular pattern cannot

Re: [Haskell-cafe] better way to do this?

2009-10-05 Thread Daniel Fischer
Am Montag 05 Oktober 2009 16:22:15 schrieb Michael Mossey: Eugene Kirpichov wrote: [x,y,t,b,l,r] - mapM (getStdRandom . randomR) [(-10,10), (-70,70), ...] return (BoxBounds ...) Thanks. I'm curious about the idea of pattern matching in do-statements that can fail. This particular pattern

[Haskell-cafe] better way to do this?

2009-10-04 Thread Michael Mossey
I'm looking for a hint to write the following code with less redundancy. I have a constructor called BoxBounds, and I want to make one with random values. randomBox :: IO BoxBounds randomBox = do x - getStdRandom (randomR (-10,10)) y - getStdRandom (randomR (-70,70)) t - getStdRandom

Re: [Haskell-cafe] better way to do this?

2009-10-04 Thread Eugene Kirpichov
[x,y,t,b,l,r] - mapM (getStdRandom . randomR) [(-10,10), (-70,70), ...] return (BoxBounds ...) 2009/10/4 Michael Mossey m...@alumni.caltech.edu: I'm looking for a hint to write the following code with less redundancy. I have a constructor called BoxBounds, and I want to make one with random

Re: [Haskell-cafe] better way to do this?

2009-10-04 Thread Felipe Lessa
On Sun, Oct 04, 2009 at 01:55:11PM +0400, Eugene Kirpichov wrote: [x,y,t,b,l,r] - mapM (getStdRandom . randomR) [(-10,10), (-70,70), ...] return (BoxBounds ...) import Control.Applicative let f = getStdRandom . randomR g1 = \x - f (-x,x) g2 = f (5,10) in BoxBounds $ g1 10 * g1 70 * g2

Re: [Haskell-cafe] better way to do this?

2009-10-04 Thread Duncan Coutts
On Sun, 2009-10-04 at 02:52 -0700, Michael Mossey wrote: I'm looking for a hint to write the following code with less redundancy. I have a constructor called BoxBounds, and I want to make one with random values. randomBox :: IO BoxBounds randomBox = do x - getStdRandom (randomR (-10,10))

Re: [Haskell-cafe] better way to do this?

2009-10-04 Thread Michael Mossey
Duncan Coutts wrote: On Sun, 2009-10-04 at 02:52 -0700, Michael Mossey wrote: I'm looking for a hint to write the following code with less redundancy. I have a constructor called BoxBounds, and I want to make one with random values. randomBox :: IO BoxBounds randomBox = do x - getStdRandom

Re: [Haskell-cafe] better way to do this?

2009-10-04 Thread Duncan Coutts
On Sun, 2009-10-04 at 05:11 -0700, Michael Mossey wrote: Duncan Coutts wrote: Others have already answered but I'd like to suggest that you avoid using IO here. There's no need for this to be impure. Can you point me to a tutorial that covers the basics of randomness in Hasell? I find it

Re: [Haskell-cafe] better way to do this?

2009-10-04 Thread Ryan Ingram
And, to go further, once you embrace determinism in your randomness, you can do all sorts of really cool things. From the perspective of a games programmer: You can run the same simulation code on two different network nodes, and reliably get the same result, allowing you to just transfer user