-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | memoize functions using SQLite3 database -- -- memoize functions using SQLite3 database @package memo-sqlite @version 0.1 -- | Memoize functions in a SQLite3 database. -- -- The functions memoized while having type f :: k -> IO v -- must result in the same output given the same input, otherwise all -- kinds of wrongness will result. -- -- The cleanup action returned by the memoizers must not be -- called if you are going to use the memoized function again; beware. -- -- An example program (included in the examples directory) might look -- like: -- --
--   -- fib.hs
--   import Data.Memo.Sqlite (memoRec', readShow, table)
--   
--   import Control.Monad (liftM2)
--   import System.Environment (getArgs)
--   
--   fib :: (Integer -> IO Integer) -> Integer -> IO Integer
--   fib _fib' n@0 = print n >> return 0
--   fib _fib' n@1 = print n >> return 1
--   fib  fib' n   = print n >> liftM2 (+) (fib' (n - 1)) (fib' (n - 2))
--   
--   main :: IO ()
--   main = do
--     [file, ts, ns] <- getArgs
--     let Just t = table ts
--         n = read ns
--     (cleanup, fib') <- memoRec' readShow file t fib
--     fib' n >>= \nth -> putStrLn $ "fib(" ++ show n ++ ") = " ++ show nth
--     cleanup
--   
-- -- Example usage: -- --
--   ghc --make fib.hs
--   ./fib fibs.sqlite3 fibs 10
--   ./fib fibs.sqlite3 fibs 10
--   ./fib fibs.sqlite3 fibs 100
--   ./fib fibs.sqlite3 fibs 100
--   
-- -- See also: -- -- module Data.Memo.Sqlite -- | A valid SQLite3 table name. data Table -- | Construct a table name. table :: String -> Maybe Table -- | Database (de)serialization class Sqlite t toSqlite :: Sqlite t => t -> SQLData fromSqlite :: Sqlite t => SQLData -> t type Wrap s t k v = (k -> IO v) -> s k -> IO (t v) type Unwrap s t k v = (s k -> IO (t v)) -> k -> IO v type Wrapper s t k v = (Wrap s t k v, Unwrap s t k v) -- | Use Read and Show for database (de)serialization. data ReadShow t -- | Wrapper using Read and Show for (de)serialization of both keys and -- values. readShow :: Wrapper ReadShow ReadShow k v type Memo k v = (k -> IO v) -> IO (IO (), k -> IO v) type MemoRec k v = ((k -> IO v) -> k -> IO v) -> IO (IO (), k -> IO v) type MkMemo k v = FilePath -> Table -> Memo k v type MkMemoRec k v = FilePath -> Table -> MemoRec k v -- | Memoize a function using an SQLite3 database. memo :: (Sqlite k, Sqlite v) => MkMemo k v -- | Memoize a recursive function using an SQLite3 database. memoRec :: (Sqlite k, Sqlite v) => MkMemoRec k v -- | Memoize a function using an SQLite3 database, using the supplied -- wrapper for control of (de)serialization. memo' :: (Sqlite (s k), Sqlite (t v)) => Wrapper s t k v -> MkMemo k v -- | Memoize a recursive function using an SQLite3 database, using the -- supplied wrapper for control of (de)serialization. memoRec' :: (Sqlite (s k), Sqlite (t v)) => Wrapper s t k v -> MkMemoRec k v data SQLData :: * SQLInteger :: Int64 -> SQLData SQLFloat :: Double -> SQLData SQLText :: String -> SQLData SQLBlob :: ByteString -> SQLData SQLNull :: SQLData instance Eq Table instance Ord Table instance Show Table instance (Read t, Show t) => Sqlite (ReadShow t)