Re: [Haskell-cafe] Can anyone help me with partition numbers?

2005-11-25 Thread Fan Wu
partition n = part n $ map (:[]) [1..n] where part n [] = [] part n (x:xs) | s == n= x: r | s > n = r | otherwise = foldr (:) (part n $ map (:x) [h..n-1]) r w

Re: [Haskell-cafe] questions on lazy pattern, StateT monad

2005-11-24 Thread Fan Wu
> Yes, but this StateT type application cannot be equal to the outer StateT type > application because this would result in an infinite type which Haskell > doesn't support. Example: > > StateT Int (StateT Int (StateT Int ...)) I see. I was trying to justify the lazy pattern in this mplus,

Re: [Haskell-cafe] questions on lazy pattern, StateT monad

2005-11-24 Thread Fan Wu
> They cannot belong to the same monad. If s is the state type and m1' and m2' > belong to the monad m then m1 and m2 belong to the monad StateT s m. I know it looks insane, I'm just trying to make a recursive case of it: technically it's still possible to have a StateT monad as the m in "StateT

Re: [Haskell-cafe] questions on lazy pattern, StateT monad

2005-11-24 Thread Fan Wu
> They are useful not only in conjunction with infinite data structures. Take > my example state transformer "everything" and modify it so that it calls next > exactly two times, not infinitely many times, and outputs a pair of the > outputs of the two next invocations. > > Now let's assume you us

Re: [Haskell-cafe] questions on lazy pattern, StateT monad

2005-11-24 Thread Fan Wu
> But I think the reasons behind lazy pattern usage in the mplus > implementation are similar to those behind lazy pattern usage in the (>>=) > implementation. I find the explanation of "Lazy patterns are useful in contexts where infinite data structures are being defined recursively" is easier to

Re: [Haskell-cafe] questions on lazy pattern, StateT monad

2005-11-24 Thread Fan Wu
Hi Wolfgang, I think you have a very good point. I'll buy it:-) > [There is a "do" missing before the lazy pattern, isn't it?] That's right! Thanks! Fan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/has

Re: [Haskell-cafe] questions on lazy pattern, StateT monad

2005-11-24 Thread Fan Wu
Hi Wolfgang, I don't know the history so maybe this is a new implementation of State transformer. The Peek and poke functions are defined below (copied from StateT.hs): instance Monad m => StateM (StateT s m) s where peek = S (\s -> return (s,s)) poke s= S (\s1 -> ret

Re: [Haskell-cafe] questions on lazy pattern, StateT monad

2005-11-23 Thread Fan Wu
Hi Wolfgang, Thanks for your response and examples! It helps a lot. >From your example I can see "Lazy patterns are useful in contexts where infinite data structures are being defined recursively" (quote section 4.4 of Gentle Introduction to Haskell). But does it apply to the mplus case? I mean t

Re: [Haskell-cafe] questions on lazy pattern, StateT monad

2005-11-23 Thread Fan Wu
On 11/23/05, Wolfgang Jeltsch <[EMAIL PROTECTED]> wrote: > Am Mittwoch, 23. November 2005 10:03 schrieb Fan Wu: > > [...] > > > I'm puzzled over this line: > > > > ~(a,s') <- lift (mplus m1' m2') > > Why is this line in Mona

[Haskell-cafe] questions on lazy pattern, StateT monad

2005-11-23 Thread Fan Wu
Hi Haskell gurus, I'm very puzzled on some code I saw in GHC Monad.StateT (which is about state monad transformers) source and hope you can kindly give me some insight into this. newtype StateT s m a = S (s -> m (a,s)) instance MonadPlus m => MonadPlus (StateT s m) where mzero = l

[Haskell-cafe] Monad Transformer question

2005-11-22 Thread Fan Wu
Hi Haskell gurus, I'm learning Haskell now and here I'm quite puzzled over some code about Monad Transformers. The code is like: type NDS a = StateT ProblemState [] a getVar :: Var -> NDS (Maybe Value) getVar v = do vs <- gets vars return $ lookup v vs What puzzles m