Sure enough:
Something like:
pipeScore = go
where
go b = do
x <- await
case x of
Left s -> yield (Left s) -- Right here
I marked the location where I did not add the required loop back to go.
On Mon, May 12, 2014 at 11:14 AM, Pierre R <[email protected]> wrote:
> @Patrick: as a note I have just reverted your suggested change about
> keeping one loop level only. In your implementation if the previous pipe
> (`pipeRead`) fails with a Left, the game exits whereas the intended
> behavior is to keep running it displaying the left msg.
>
>
> On Monday, May 12, 2014 5:19:50 PM UTC+2, Pierre R wrote:
>>
>> I have just updated the code (on my repo that contains MVC.hs) so that
>> the end of game is now considered a Right value.
>>
>> So I have introduced the type:
>> data ScoreBoard = Done Int | Current (Int, Board) deriving (Show, Eq)
>>
>> and `score` has now this signature:
>> score :: Int -> Board -> Either String ScoreBoard
>>
>> These changes have cleaned up the MVC code a bit (for instance it does
>> not need to know about `isGameOver` anymore)
>>
>> `pipeScore` is even more stupid than before so there must be a better
>> way to re-conciliate the APIs.
>>
>> pipeScore :: (Monad m) => Board -> Pipe (Either String Int) (Either String
>> ScoreBoard) 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 c@(Current (_, b')) -> do
>> yield (Right c)
>> go b'
>> Right (Done s) ->
>> yield $ Right (Done s)
>> Left msg -> do
>> yield (Left msg)
>> go b
>>
>>
>> @Patrick, my repos contain the merged code:
>> https://github.com/PierreR/afgame/tree/master/haskell
>>
>> I will probably follow your advice about keeping only one level of loop.
>> I still don't get how to apply `right` from pipe-extra though (your
>> pipeScore' doesn't compile). I will give it another try as soon as I
>> understand this better. Thanks for your help.
>>
>> Cheers
>>
>> On Sunday, May 11, 2014 2:39:50 PM UTC+2, Davorak wrote:
>>>
>>> @Tony - I am getting a 404 for that link[1]. The base repo is there by
>>> I can not find the MVC example with a github search.
>>>
>>> [1]https://github.com/tonyday567/afgame/blob/mvc-
>>> example/haskell/src/Afgame/MVC.hs
>>>
>>> On Wed, May 7, 2014 at 10:51 PM, Tony Day <[email protected]> wrote:
>>>
>>>> Hi Pierre,
>>>>
>>>> I coded up your front-end in the spirit of Gabe's mvc library. I know
>>>> you didn't ask that, of course, but G has asked for examples of using the
>>>> mvc library and your example was perfect for the task.
>>>>
>>>> https://github.com/tonyday567/afgame/blob/mvc-example/
>>>> haskell/src/Afgame/MVC.hs
>>>>
>>>> I liked how it turned out. Most of the IO in the existing pipes became
>>>> messages that get wrapped as part of an Either String (Int,Board). Not
>>>> perfect but, with the pipeline getting a bit messier.
>>>>
>>>> Most fun was using quickcheck on the game logic. I can guess from qc
>>>> that the game lasts for 15 moves, that a high score is around 200, and that
>>>> moves of 15 and consecutive moves that add up to 15 are strong. Not bad
>>>> considering I haven't even read the rules!
>>>>
>>>>
>>>> On Tuesday, May 6, 2014 5:32:37 AM UTC+10, Pierre R wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> I have added a little pipes frontend to one of my pet example and I
>>>>> was wondering how idiomatic (or not) it is.
>>>>>
>>>>> http://lpaste.net/103623
>>>>>
>>>>> Basically instead of consuming a list with mapM (the `scores`
>>>>> function) I am streaming input from stdin. Consequently I need to treat
>>>>> the
>>>>> end of game differently than a bogus shot.
>>>>>
>>>>> Nothing to do with Pipes but I am not sure annotation 2 is better
>>>>> because it forces all client `score` code to unwrap StateT whereas I only
>>>>> need the state monad when I have to deal with a list of shots. Is there a
>>>>> more idiomatic way to do this ?
>>>>>
>>>>> The github repo is here : https://github.com/PierreR/afg
>>>>> ame/tree/master/haskell
>>>>>
>>>>> Thanks for your feedback
>>>>>
>>>> --
>>>> 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].
>>>>
>>>
>>>
>>>
>>> --
>>> Patrick Wheeler
>>> [email protected]
>>> [email protected]
>>> [email protected]
>>>
>> --
> 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].
>
--
Patrick Wheeler
[email protected]
[email protected]
[email protected]
--
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].