Redux 스타일 store 는 상태 하나와 리스너 목록 하나다. dispatch(action) 은 reducer(지금 상태, action) 으로 새 상태를 만들어 갈아 끼우고, 리스너 전부에게 새 상태를 알린 뒤 action 을 돌려준다. subscribe 는 리스너를 곧바로 지금 상태로 한 번 부르고 목록에 넣으며, 목록에서 빼는 함수를 돌려준다. getState 는 지금 상태를 읽는다.

-- 간단한 Redux 스타일 store: 상태 하나 + 리스너 목록 하나
createStore :: (s -> a -> s) -> s -> Store s a
createStore reducer s0 = Store { getState, subscribe, dispatch }   -- s0: 만들 때 리듀서와 함께 넘기는 초기 상태 (preloadedState)
  where
    getState      = read state
    dispatch a    = do s' <- reducer <$> read state <*> pure a
                       state := s'
                       mapM_ ($ s') =<< read listeners
                       pure a
    subscribe l   = do l =<< read state          -- 지금 상태로 한 번 곧바로
                       listeners %= (l :)
                       pure (listeners %= filter (/= l))   -- 해지 함수
`#529`