Random walk on a pointed container
问题 Let us consider a dwarf wandering in a tunnel. I will define a type that represents this situation thusly: data X a = X { xs :: [a], i :: Int } display :: X Bool -> IO () display X{..} = putStrLn (concatMap f xs) where { f True = "*" ; f False = "-" } Here you see a dwarf in a section of a tunnel: λ display x -*--- It is discovered that a pointed container is an instance of Comonad. I can use this instance here to define a function that simulates my dwarf moving right: shiftRight :: X Bool ->