[Haskell-cafe] Tutorial: Haskell for the Evil Genius
Benjamin L. Russell
DekuDekuplex at Yahoo.com
Sat Oct 13 14:17:24 CEST 2012
> I found some useful reference code on the Haskell Wiki and constructed my own
> memoized Fibonacci function using the MemoTrie library, which, fortunately, is
> builtin with Haskell Platform and therefore does not require the tutorial
> reader to install additional code.
> The new version of the tutorial includes an ordinary recursive Fibonacci
> function (fib1.hs), and the same code but renamed to fib', memoized using the
> memo function from the MemoTrie library (fib2.hs), and exposed as fib. Unix
> time information provides real numbers for comparison: The memoized version is
> clearly much faster.
> I rewrote the section, deleting the part that stated memoization was automatic,
> and added text describing how Haskell makes memoization easy.
Which version of the Haskell Platform are you using? I tried running
your memoized Fibonacci function that uses the MemoTrie library on
Windows XP with Service Pack 3, and received the following error
> $>./runhaskell fib2
> Could not find module `Data.Memotrie':
> Use -v to see a list of the files searched for.
My version is as follows:
> $>./ghci -v
> GHCi, version 6.12.3: http://www.haskell.org/ghc/ :? for help
> Glasgow Haskell Compiler, Version 6.12.3, for Haskell 98, stage 2 booted by GHC
> version 6.10.4
> Using binary package database: C:\PROGRA~1\HASKEL~1\201020~1.0\lib\package.conf.
> hiding package base-220.127.116.11 to avoid conflict with later version base-18.104.22.168
> wired-in package ghc-prim mapped to ghc-prim-0.2.0.0-2feb0cb38f65a4827135ada88c3
> wired-in package integer-gmp mapped to integer-gmp-0.2.0.1-72436e28c79d056c87cc0
> wired-in package base mapped to base-22.214.171.124-0d1804f62045e52b2e806996d84f5318
> wired-in package rts mapped to builtin_rts
> wired-in package haskell98 mapped to haskell98-126.96.36.199-b5196101fd7a8c42a8d53bd80
> wired-in package template-haskell mapped to template-haskell-188.8.131.52-401621dedd4
> wired-in package dph-seq mapped to dph-seq-0.4.0-be069f0bb710922a6ddd4ed2b91e3a6
> wired-in package dph-par mapped to dph-par-0.4.0-b31a0ce10b7c92126978fcc929077ad
> Hsc static flags: -static
> Loading package ghc-prim ... linking ... done.
> Loading package integer-gmp ... linking ... done.
> Loading package base ... linking ... done.
> Loading package ffi-1.0 ... linking ... done.
For reference, my code is as follows:
> #!"c:/Program Files/Haskell Platform/2010.2.0.0/bin/" runhaskell
> import Data.Memotrie (memo)
> fib :: Int -> Int
> fib = memo fib'
> fib' :: Int -> Int
> fib' 0 = 0
> fib' 1 = 1
> fib' n = fib' (n - 1) + fib' (n - 2)
> main :: IO ()
> main = do
> putStrLn (show (fib 30))
-- Benjamin L. Russell
Benjamin L. Russell / DekuDekuplex at Yahoo dot com
Translator/Interpreter / Mobile: +011 81 90-6526-1406
"Furuike ya, kawazu tobikomu mizu no oto." -- Matsuo Basho^
More information about the Haskell-Cafe