on master help sign in
Some comments for pidigits
commit3835dce242561eae5d8849ca6f73e2f66e6c6969 authorSebastian de Bellefon <arnaudpourseb@gmail.com> dateThu 25 Sep 2014, 18:56 (12 years ago) parent6e9ae3e
1 file changed+14
benchmarks/pidigits/pidigits.idr+14
benchmarks/pidigits/pidigits.idr+14
@@ -1,7 +1,20 @@
11import System
22
3+{- Toy program that outputs the n first digits of Pi.
4+
5+ Inspired from http://www.haskell.org/haskellwiki/Shootout/Pidigits.
6+ The original ns and str lazy lists have been replaced by strict functions.
7+
8+ Memory usage seems to be excessive. One of the branches of str is tail recursive, and
9+ the other one only needs to cons an extra Integer.
10+
11+ For reference, the Haskell version runs in 0m0.230s when printing to /dev/null.
12+ It almost runs in constant space.
13+-}
14+
315data F = mkF Integer Integer Integer
416
17+-- Prints the list of digits by groups of 10
518loop : Nat -> Nat -> List Integer -> IO()
619loop n k' Nil = putStrLn $ (pack $ Vect.replicate n ' ') ++ "\t:" ++ show k'
720loop Z k' xs = do putStrLn ("\t:"++show k')
@@ -18,6 +31,7 @@ flr x (mkF q r t) = (q*x + r) `div` t
1831comp : F -> F -> F
1932comp (mkF q r t) (mkF u v x) = mkF (q*u) (q*v+r*x) (t*x)
2033
34+-- Returns the list of digits of pi. Memory hungry.
2135str : F -> Integer -> Nat -> List Integer
2236str _ _ Z = Nil
2337str z k (S n) = if(y == flr 4 z)