Source

xp.memo / code / Main.hs

module Main where
  
import qualified Memo.SNMap.SNMap as S ( memo )

import qualified Memo.Tries.Conal as C ( memo , untrie , trie ) 

import Debug.Trace ( trace )

import System.Vacuum.Ubigraph ( view )

import System.IO (BufferMode (NoBuffering), hSetBuffering , stdout)

main = do hSetBuffering stdout NoBuffering
          putStrLn "--"
          print (mfib' 30000)
          putStrLn "--"
          print (mfib' 30003)
          
memoTrace = C.untrie . (trace "Building trie" C.trie)

mfib :: Integer -> Integer
mfib = memoTrace mfib'

mfib' :: Integer -> Integer
mfib' 0 = 0
mfib' 1 = 1
mfib' n = mfib (n-2) + mfib (n-1)


snfib :: Integer -> Integer
snfib = S.memo sfib

sfib 0 = 0
sfib 1 = 1
sfib n = snfib (n-2) + snfib (n-1)

memostring :: String -> String
memostring = C.memo reverse