Re: [Haskell-cafe] Re: Bound threads

2005-03-02 Thread Wolfgang Thaller
Marcin Kowalczyk wrote: Indeed, my brain is melting, but I did it :-) Congratulations. How about we found a "Bound-thread-induced brain melt victims' support group"? [...] I have added some optimizations: I think we had thought of most of these optimizations, but things were already very complex

Re: [Haskell-cafe] State Monad

2005-03-02 Thread Mark Carroll
On Thu, 3 Mar 2005, Sam G. wrote: > I need a Monad to represent an internal stack. I mean I've got a lot > of functions which operates on lists and I would not like to pass the > list as an argument everytime. > > Could you help me writing this monad? To start, I just need a + > function which wi

Re: [Haskell-cafe] State Monad

2005-03-02 Thread Bernard Pope
On Thu, 2005-03-03 at 02:03 +0100, Sam G. wrote: > I need a Monad to represent an internal stack. I mean I've got a lot of > functions which operates on lists and I would not like to pass the list as an > argument everytime. > > Could you help me writing this monad? To start, I just need a + fu

Re: [Haskell-cafe] State Monad

2005-03-02 Thread Sam
Hello again, in fact I wrote the following state monad: -- newtype State state value = State (state -> (state, value)) instance Monad (State state) where return v = State $ \s -> (s, v) State f >>= k = State $ \s -> let (s0, v0) = f s State g = k v0

[Haskell-cafe] State Monad

2005-03-02 Thread Sam G.
I need a Monad to represent an internal stack. I mean I've got a lot of functions which operates on lists and I would not like to pass the list as an argument everytime. Could you help me writing this monad? To start, I just need a + function which will return the sum of the 2 toppest elements

Re: [Haskell-cafe] Re: Bound threads

2005-03-02 Thread Marcin 'Qrczak' Kowalczyk
"Simon Marlow" <[EMAIL PROTECTED]> writes: >> I've now implemented a threaded runtime in my language Kogut, based >> on the design of Haskell. The main thread is bound. The thread which >> holds the capability performs I/O multiplexing itself, without a >> separate service thread. > > We found tha

Re: [Haskell-cafe] how do I avoid excessive constructor application?

2005-03-02 Thread Keean Schupke
Something like: class Coerce a b where coerce :: a -> b The class must be in a separate file from the instance so that the compiler does not determine that a == b for all instances. instance Coerce a a where coerce = id If it turns out the left and right types do not match, you get a "no inst

Re: [Haskell-cafe] how do I avoid excessive constructor application?

2005-03-02 Thread Lemmih
On Wed, 2 Mar 2005 15:54:51 +0100, Stefan Holdermans <[EMAIL PROTECTED]> wrote: > Lemmih, > > > And you can "fix" it with some unsafeCoerce# magic. (: > > Actually, as I pointed out, the required coercion in perfectly safe, > though not implicit: > > coerceRight :: Either a b -> Either c b > coe

Re: [Haskell-cafe] how do I avoid excessive constructor application?

2005-03-02 Thread S. Alexander Jacobson
I'd like to do this sort of thing with types other than Either. Is there a generic safe coerce function? -Alex- On Wed, 2 Mar 2005, Stefan Holdermans wrote: Lemmih, And you can "fix" it with some unsafeCoerce# magic. (: Actually, as I pointed out, the required coercion in perfectly safe, though no

Re: [Haskell-cafe] how do I avoid excessive constructor application?

2005-03-02 Thread Stefan Holdermans
Lemmih, And you can "fix" it with some unsafeCoerce# magic. (: Actually, as I pointed out, the required coercion in perfectly safe, though not implicit: coerceRight :: Either a b -> Either c b coerceRight (Right b) = Right b Regards, Stefan ___ Haskell-

Re: [Haskell-cafe] how do I avoid excessive constructor application?

2005-03-02 Thread Lemmih
On Wed, 2 Mar 2005 09:20:15 -0500 (Eastern Standard Time), S. Alexander Jacobson <[EMAIL PROTECTED]> wrote: > My point was that this code seems excessively complex: > >fun::(a->a1)->(Either a b)->Either a1 b >fun f (Left x) = Left (f x) >fun _ r@(Right x)= Right x > > I'd like to avoi

Re: [Haskell-cafe] how do I avoid excessive constructor application?

2005-03-02 Thread Stefan Holdermans
Alex, fun::(a->a1)->(Either a b)->Either a1 b fun f (Left x) = Left (f x) fun _ r@(Right x)= Right x I'd like to avoid the destruction and construction in the third line by replacing the right hand side with r. However, the typechecker then claims my type is wrong. How do I fix that? You c

Re: [Haskell-cafe] how do I avoid excessive constructor application?

2005-03-02 Thread S. Alexander Jacobson
My point was that this code seems excessively complex: fun::(a->a1)->(Either a b)->Either a1 b fun f (Left x) = Left (f x) fun _ r@(Right x)= Right x I'd like to avoid the destruction and construction in the third line by replacing the right hand side with r. However, the typechecker then c

RE: [Haskell-cafe] Re: Bound threads

2005-03-02 Thread Simon Marlow
On 01 March 2005 11:21, Marcin 'Qrczak' Kowalczyk wrote: > Marcin 'Qrczak' Kowalczyk <[EMAIL PROTECTED]> writes: > >> Why is the main thread bound? > > I can answer myself: if the main thread is unbound, the end of the > program can be reached in a different OS thread, which may be a > problem i

Re: [Haskell-cafe] Numeric vs. relative precedences of infix operators

2005-03-02 Thread Henning Thielemann
On Wed, 2 Mar 2005, Benjamin Franksen wrote: > There is a good argument for 'distfix' i.e. bracketing operators, IMO. You > could define your own if_then_else: > > `if cond `then` truebranch `else` falsebranch end` I would be more happy with if :: Bool -> a -> a -> a if True x _ = x if F

Re: [Haskell-cafe] how do I avoid excessive constructor application?

2005-03-02 Thread Henning Thielemann
On Wed, 2 Mar 2005, Ben Lippmeier wrote: > You can play games with the type checker to force them to have the same > type without changing the "meaning" of your function. > > fun1' f (Left x)= if True then Left (f x) else Left x Left (f x) `asTypeOf` Left x ? __