Skip to content

Instantly share code, notes, and snippets.

View wuerges's full-sized avatar

Emilio Wuerges wuerges

  • Home
  • Santa Catarina - Brazil
View GitHub Profile
@ramntry
ramntry / automemoization.hs
Last active September 25, 2022 13:05
Auto-memoization in Haskell by State monad
import Control.Monad.State
import qualified Data.Map as Map
recall :: Ord a => a -> State (Map.Map a r) (Maybe r)
recall n = do
memory <- get
return (Map.lookup n memory)
memorize :: Ord a => a -> r -> State (Map.Map a r) ()
memorize n result = do