The code compiles but when run gets stuck in infinite recursive loop. It's not obvious where the loop enters, especially when using recursive do or monadfix. When trying to debug in the browser it finds cyclic evaluation in fixIO at rts.js line 6086
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecursiveDo #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE MonoLocalBinds #-}
import Reflex.Dom
import qualified Data.Text as T
main :: IO ()
main = mainWidget game
game :: MonadWidget t m => m ()
game = elClass "div" "game" $ do
elClass "div" "game-board" $ do
rec
stateEv <- board stateEv [["","",""],["","",""],["","",""]]
elClass "div" "game-info" $ do
elClass "div" "statu" $ blank
elClass "ol" "todo" $ blank
board :: MonadWidget t m
=> [[Event t T.Text]]
-> [[T.Text]]
-> m [[(Event t T.Text)]]
board s iss = elClass "div" "board" $ do
el "div" $ do
elClass "div" "status" $ text "Next player: X"
mapM (boardRow s) iss
boardRow :: MonadWidget t m
=> [[Event t T.Text]]
-> [T.Text]
-> m [(Event t T.Text)]
boardRow s is = elClass "div" "board-row" $ mapM (square s) is
square :: (
PostBuild t m
, DomBuilder t m
, MonadHold t m
)
=> [[Event t T.Text]]
-> T.Text
-> m (Event t T.Text)
square stateEv i = do
rec
let ev = domEvent Click e
ev' = updated dyn
ev'' = tagPromptlyDyn dyn ev
dyn = tooglePlayer <$> dynBool
dyns <- mapM (holdDyn i) (concat stateEv)
dynBool <- toggle True $ updated $ distributeListOverDyn dyns
(e, _) <- elAttr' "button" ("type" =: "button" <> "class" =: "square") $ dynText dyn
return ev''
tooglePlayer :: Bool -> T.Text
tooglePlayer True = "X"
tooglePlayer False = "O"