So the best I could come up with is:

untilDone :: Monad m => Pipe (Either String ScoreBoard) (Either String 
ScoreBoard) m ()
untilDone = do
    x <- await
    yield x
    case x of
        Right (Done _) -> return ()
        _              -> untilDone

pipeScore :: (Monad m) => Pipe (Either String Int) (Either String 
ScoreBoard) m  ()
pipeScore = (flip S.evalStateT) emptyBoard go 
    where
        go =  do
            x <- lift $ await
            case x of
                Left s -> lift $ yield (Left s)
                Right n -> do
                    b <- S.get
                    let y = score n b
                    lift $ yield y
                    case y of
                        Right (Current (_, b')) -> do S.put b'; go
                        _                       -> return ()


Then 
model :: Model Board String (Either String ScoreBoard)
model = asPipe (pipeQuit >-> pipeRead >-> pipeScore >-> untilDone)

On Tuesday, May 13, 2014 12:12:21 PM UTC+2, Pierre R wrote:
>
>
>
>>     pipeScore :: (Monad m) => Board -> Pipe (Either String Int) (Either 
>> String ScoreBoard) m ()
>>     pipeScore = evalStateT $ for untilDone $ \x -> case x of
>>         Left  s -> lift $ yield (Left s)
>>         Right n -> do
>>             let y = score n b
>>             lift $ yield y
>>             case y of
>>                 Right (Current (_, b')) -> put b'
>>                 _                       -> return ()
>>
>>  
> This does not seem to compile. 
>   - `for` returns a Pipe, not a StateT
>   -  `n` coming from `untilDone` is actually `ScoreBoard`, not an `Int`.
>
> I am still trying to figure it out alone but with no luck so far ;-)
> For instance, this one compiles but does not output anything
>
> pipeScore :: (Monad m) => Board -> Pipe (Either String Int) (Either String 
> ScoreBoard) m ()
> pipeScore = S.evalStateT $ forever $ do 
>     x <- lift $ await
>     case x of
>         Left  s -> lift $ yield (Left s)
>         Right n -> do
>             b <- S.get 
>             let y = score n b
>             lift $ yield y
>             case y of
>                 Right (Current (_, b')) -> S.put b'
>                 _                       -> return ()
>

-- 
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