Re: Stack usage with a state monad

2003-12-31 Thread Graham Klyne
I've read 4 messages following this, but I'd like to pursue this a little to test my own understanding... At 14:12 30/12/03 +, Joe Thornber wrote: I was wondering if anyone could give me some help with this problem ? I'm trying to hold some state in a StateMonad whilst I iterate over a large

Re: Stack usage with a state monad

2003-12-31 Thread Joe Thornber
On Wed, Dec 31, 2003 at 11:54:27AM +, Graham Klyne wrote: > My *intuition* here is that the problem is with countLeaves2, in that it > must build the computation for the given [sub]tree before it can start to > evaluate it. Maybe this is why other responses talk about changing the > state m

Re: Stack usage with a state monad

2003-12-31 Thread Graham Klyne
At 12:36 31/12/03 +, Joe Thornber wrote: On Wed, Dec 31, 2003 at 11:54:27AM +, Graham Klyne wrote: > My *intuition* here is that the problem is with countLeaves2, in that it > must build the computation for the given [sub]tree before it can start to > evaluate it. Maybe this is why other r

Re: Stack usage with a state monad

2003-12-31 Thread Joe Thornber
On Wed, Dec 31, 2003 at 02:38:06PM +, Graham Klyne wrote: > getOrCachePositionValue pos = > do { mcache <- gets (findPos pos) -- Query cache for position >; case mcache of >Just cached -> return (cachedVal cached) -- Return cached value >Nothing ->

Type checking

2003-12-31 Thread Lee Dixon
Hi, Can anyone explain to me how hugs manages to derive that f x y z = y (y z) x is of type f :: a -> ((a -> b) -> a -> b) -> (a -> b) -> b Many thanks and a happy new year to all! Lee _ Stay in touch with absent friends - get M

Re: Type checking

2003-12-31 Thread Jon Fairbairn
On 2003-12-31 at 19:27GMT "Lee Dixon" wrote: > Hi, > > Can anyone explain to me how hugs manages to derive that > > f x y z = y (y z) x > > is of type > > f :: a -> ((a -> b) -> a -> b) -> (a -> b) -> b To begin with, f has three arguments, x y and z, so letting each of these have types Tx Ty

Monads

2003-12-31 Thread Mark Carroll
Omitting the typeclass bit, I'm trying to write something like (s1 -> s2) -> StateT s1 m () -> StateT s2 m a -> StateT s1 m a That is, it sequences two StateT computations, providing a way to translate from the first's state to the second to keep the chain going. I can easily write something for

Parsec question

2003-12-31 Thread Mark Carroll
I tried posting this before but, from my point of view, it vanished. My apologies if it's a duplicate. In http://www.cs.uu.nl/~daan/download/parsec/parsec.html we read, > testOr2 = try (string "(a)") > <|> string "(b)" > > or an even better version: > > testOr3 = do{ try (string "(a")

Re: Monads

2003-12-31 Thread Christopher Milton
Mark, I'm no expert, but does it help to start from withStateT? > withStateT :: (s -> s) -> StateT s m a -> StateT s m a > withStateT f m = StateT $ runStateT m . f There are some notes about computations and lifting state transformers in Modular Denotational Semantics for Compiler Construction

Re: Monads

2003-12-31 Thread Ken Shan
Mark Carroll <[EMAIL PROTECTED]> wrote in article <[EMAIL PROTECTED]> in gmane.comp.lang.haskell.cafe: > Omitting the typeclass bit, I'm trying to write something like > (s1 -> s2) -> StateT s1 m () -> StateT s2 m a -> StateT s1 m a > > That is, it sequences two StateT computations, providing a w

Re: Monads

2003-12-31 Thread Mark Carroll
On Wed, 31 Dec 2003, Ken Shan wrote: > Don't you need a (s2 -> s1) function as well, to translate the final > state back into StateT s1? Yes, you're right: the thing actually running the stateful computation presumably expects to start it with a state of type s1 and to be able to extract from it