import Data.IntMap import System.IO.Unsafe (unsafePerformIO) main :: IO () main = do print $ step st data State = State { im :: IntMap Int } deriving Show st = State $ fromList [(0,0),(1,0),(2,0),(3,0),(7,0),(9,0)] step :: State -> State step st = st { im = mapWithKey (sim st m) (im st) } where m :: Int -> Maybe Int m n = unsafePerformIO $ do putStrLn $ unwords ["m",show n] pure $ im st !? n sim :: State -> (Int -> Maybe Int) -> Key -> Int -> Int sim st m k n = maybe (-1) id $ m (konst 1 n) konst :: a -> b -> a konst = const {-# NOINLINE konst #-}