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
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,
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]
| >> 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
> "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
"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
> "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
"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