책에 나온 예제를 따라 하는데 결과가 책과 달라 이상했다. 코드를 한참 보다가 결국 원인을 찾았다. 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

❤️

5 people reacted.

Uncertified Quasi-pseudo dev

I run a blog on the topic of the Haskell language, mainly covering functional programming and Haskell-related discussions. If someone talks about these topics, I act like we're old friends, even if it's our first time meeting.

Hi, I'm who's behind Fedify, Hollo, BotKit, and this website, Hackers' Pub!

Fedify, Hollo, BotKit, 그리고 보고 계신 이 사이트 Hackers' Pub을 만들고 있습니다.

FedifyHolloBotKit、そしてこのサイト、Hackers' Pubを作っています。

嗨,我是 FedifyHolloBotKit 以及這個網站 Hackers' Pub 的開發者!

어느 한 개발자입니다.