In the

On Saturday, May 10, 2014 2:01:04 AM UTC+2, Gabriel Gonzalez wrote:
>
>  Sorry for the late response, but I was busy preparing for BayHac.
>
> I really loved Tony's `mvc`-based solution (of course I'm biased).  The 
> only thing I wanted to add was the following rule of thumb for how to get 
> local vs global state.
>
> For local state, put the `StateT` layer outside the `Pipe` layer and then 
> immediately run the `StateT` layer before composing it with other pipes:
>
>     numbers :: Monad m => Producer Int m r
>     numbers = flip evalStateT 0 $ forever $ do
>         n <- get
>         lift (yield n)
>         put $! n + 1
>

For local state,  I guess a loop might be as good, isn't ?
numbers :: Monad m => Int -> Producer Int m r
numbers = go
    where
        go n = do yield n; go $! n + 1 

`PipeScore` for instance seems to be better expressed as such:
pipeScore :: (Monad m) => Board -> Pipe (Either String Int) (Either String 
(Int,Board)) m ()
pipeScore =  go
    where
        go b =  do
            for cat $ \x -> case x of
                Left s -> yield (Left s)
                Right n -> do
                    case score n b of
                        Right (a', b') -> do
                            yield (Right (a',b'))
                            if isGameOver b'
                                then yield (Left "Game over. Bye. See you 
next time")
                                else go b'
                        Left msg -> do
                            yield (Left msg)
                            go b

-- 
You received this message because you are subscribed to the Google Groups 
"Haskell Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].

Reply via email to