Re: [Haskell-cafe] Trapped by the Monads

2005-09-21 Thread Ketil Malde
Bill Wood [EMAIL PROTECTED] writes: The variable mem is a so-called hybrid variable; it crunches together 2 different concepts: a boolean value (could I allocate memory?) and an address value (what is the address where I can find my allocated memory). IMO, Maybe is exactly the oppsite, it

[Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Mark Carter
I'm puzzling out how to get a Bool from am IO Bool. I know I'm not supposed to, but I don't see any way around my predicament. The basic setup is: I have an edit box, and a panel. If you click the LMB on the panel when the edit box is checked, this means you want to move a graphical object

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Neil Mitchell
Take a look at unsafePerformIO, it is of type IO a - a. Its not particularly safe (the name gives a clue), but it does what you want. On 9/20/05, Mark Carter [EMAIL PROTECTED] wrote: I'm puzzling out how to get a Bool from am IO Bool. I know I'm not supposed to, but I don't see any way around

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread robert dockins
Mark Carter wrote: I'm puzzling out how to get a Bool from am IO Bool. I know I'm not supposed to, but I don't see any way around my predicament. The basic setup is: I have an edit box, and a panel. If you click the LMB on the panel when the edit box is checked, this means you want to move

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Piyush P Kurur
On Tue, Sep 20, 2005 at 04:30:25PM +0100, Neil Mitchell wrote: Take a look at unsafePerformIO, it is of type IO a - a. Its not particularly safe (the name gives a clue), but it does what you want. I dont think you would ever need to do unsafePerformIO unless you are writing some lib

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Mark Carter
Greg Buchholz wrote: Have you read... http://haskell.org/hawiki/ThatAnnoyingIoType Thanks. I'll take a look at it. I also need to take a look at the basic Haskell syntax. An interesting-looking web page which discusses monads is: http://www.nomaware.com/monads/html/analogy.html

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Mark Carter
Mark Carter wrote: What struck me was this bit of code: assemblyLine w = (return w) = makeChopsticks = polishChopsticks = wrapChopsticks Interestingly, this looks like Forth (!), where you put a value on the stack, and successive operations fiddle with the stack as a series of

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Bill Wood
. . . What struck me was this bit of code: assemblyLine w = (return w) = makeChopsticks = polishChopsticks = wrapChopsticks Interestingly, this looks like Forth (!), where you put a value on the stack, and successive operations fiddle with the stack as a series of

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Bill Wood
. . . Another thing I noticed in my nano-experience of Haskell is the Maybe monad. This is interesting because it's a bit like a hybrid variables. If you look at a book like Writing Solid Code (or is it Code Complete, I can't remember now) which examine C style, they basically scorn

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Lennart Augustsson
Mark Carter wrote: The typical example in C is: mem = malloc(1024) Malloc returns 0 to indicate that memory cannot be allocated, or a memory address if it can. The variable mem is a so-called hybrid variable; it crunches together 2 different concepts: a boolean value (could I allocate

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Bill Wood
. . . The typical example in C is: mem = malloc(1024) Malloc returns 0 to indicate that memory cannot be allocated, or a memory address if it can. The variable mem is a so-called hybrid variable; it crunches together 2 different concepts: a boolean value (could I allocate memory?) and

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Mark Carter
Lennart Augustsson wrote: Mark Carter wrote: The typical example in C is: mem = malloc(1024) Malloc returns 0 to indicate that memory cannot be allocated, or a memory address if it can. The variable mem is a so-called hybrid variable; it crunches together 2 different concepts: a boolean

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Michael Walter
Compare: int *p=...; int x=*p; and: let p = ... Just x = p So actually, there is few difference between dereferencing a pointer without checking for 0, and extracting the Maybe value without handling Nothing, apart from that it leads to undefined behavior in C which in fact isn't

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Greg Buchholz
Mark Carter wrote: What struck me was this bit of code: assemblyLine w = (return w) = makeChopsticks = polishChopsticks = wrapChopsticks Interestingly, this looks like Forth (!), where you put a value on the stack, and successive operations fiddle with the stack as a series of

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Glynn Clements
Mark Carter wrote: Could you briefly elaborate on what you mean by hybrid variables? According to Google, hybrid in genetics means The offspring of genetically dissimilar parents or stock, especially the offspring produced by breeding plants or animals of different varieties, species,

Re: [Haskell-cafe] Trapped by the Monads

2005-09-20 Thread Lennart Augustsson
There's a big difference. You can see you are doing something fishy, and the compiler can too, and it can warn you. -- Lennart Michael Walter wrote: Compare: int *p=...; int x=*p; and: let p = ... Just x = p So actually, there is few difference between dereferencing a