Re: oops (was: Re: if-then-else inside a "do")

2002-01-29 Thread Kevin Glynn
I think the Haskell Wiki was going to be the place to collect interesting code fragments. However, I must add that these functions are already part of the Haskell 98 standard. See the Monad module in the Library Report. cheers k Mark Carroll writes: > On Wed, 30 Jan 2002, Bernard James P

Re: oops (was: Re: if-then-else inside a "do")

2002-01-29 Thread Mark Carroll
On Wed, 30 Jan 2002, Bernard James POPE wrote: (snip) > when :: (Monad m) => Bool -> m () -> m () > when p s = if p then s else return () > > unless :: (Monad m) => Bool -> m () -> m () > unless p s= when (not p) s (snip) That's cute. People post all sorts o

oops (was: Re: if-then-else inside a "do")

2002-01-29 Thread Bernard James POPE
Oops, Thanks to Kevin who pointed out: when :: (Monad m) => Bool -> m () -> m () when p s = if p then s else return () unless :: (Monad m) => Bool -> m () -> m () unless p s= when (not p) s > So now I tend to use: > >doIf :: Monad a => Bool -> [a b]

RE: Random questions after a long haskell coding day

2002-01-29 Thread Mark P Jones
| >> Any thumb rule for using arrays? I'm expecting access to be | >> O(1), it is right? | | > In GHC, yes. | | (Shouldn't this really be required? I mean, the whole *point* of using | arrays is to have O(1) random access, isn't it?) In Hugs, no. In an ideal world, the answer would be yes, b

RE: Random questions after a long haskell coding day

2002-01-29 Thread Simon Marlow
> "Simon Marlow" <[EMAIL PROTECTED]> writes: > > >> Can we also rely on destructive updates for the monadic arrays? > > > In GHC, yes :-) > > Goodie! > > One more question: I imagine arrays give an opportunity to optimize by > unboxing the contained type -- any chance of that? How much space

Re: Random questions after a long haskell coding day

2002-01-29 Thread Ketil Z. Malde
"Simon Marlow" <[EMAIL PROTECTED]> writes: >> Can we also rely on destructive updates for the monadic arrays? > In GHC, yes :-) Goodie! One more question: I imagine arrays give an opportunity to optimize by unboxing the contained type -- any chance of that? How much space would an array of Ch

RE: Random questions after a long haskell coding day

2002-01-29 Thread Simon Marlow
> "Simon Marlow" <[EMAIL PROTECTED]> writes: > > >> Any thumb rule for using arrays? I'm expecting access to be > >> O(1), it is right? > > > In GHC, yes. > > (Shouldn't this really be required? I mean, the whole > *point* of using > arrays is to have O(1) random access, isn't it?) > > Can

Re: Random questions after a long haskell coding day

2002-01-29 Thread Ketil Z. Malde
"Simon Marlow" <[EMAIL PROTECTED]> writes: >> Any thumb rule for using arrays? I'm expecting access to be >> O(1), it is right? > In GHC, yes. (Shouldn't this really be required? I mean, the whole *point* of using arrays is to have O(1) random access, isn't it?) Can we also rely on destructi