책에 나온 예제를 따라 하는데 결과가 책과 달라 이상했다. 코드를 한참 보다가 결국 원인을 찾았다. if 분기의 결과를 반대로 적었던 것이다.

repeatUntil
  :: Monad m
  => m chunk
  -> (chunk -> Bool)
  -> (chunk -> m ())
  -> m ()
repeatUntil getChunk isEnd f =
  repeatUntilNothing getChunkMaybe f
  where
    getChunkMaybe = do
      chunk <- getChunk
      if isEnd chunk
        then return (Just chunk)
        else return Nothing

청크가 없으면 Nothing을 리턴해야 하는데 반대로 적어버린 것이다. 덕분에 시간이 모자라서 남은 연습 문제 하나는 내일로 미뤄야겠다.

5

If you have a fediverse account, you can reply to this note from your own instance. Search https://hackers.pub/ap/notes/01964452-1a4e-700e-a031-21d456af1c6b on your instance and reply to it.