summaryrefslogtreecommitdiff
path: root/progs/demo/pfac.hs
diff options
context:
space:
mode:
authorYale AI Dept <ai@nebula.cs.yale.edu>1993-07-14 13:08:00 -0500
committerDuncan McGreggor <duncan.mcgreggor@rackspace.com>1993-07-14 13:08:00 -0500
commit4e987026148fe65c323afbc93cd560c07bf06b3f (patch)
tree26ae54177389edcbe453d25a00c38c2774e8b7d4 /progs/demo/pfac.hs
Import to github.
Diffstat (limited to 'progs/demo/pfac.hs')
-rw-r--r--progs/demo/pfac.hs21
1 files changed, 21 insertions, 0 deletions
diff --git a/progs/demo/pfac.hs b/progs/demo/pfac.hs
new file mode 100644
index 0000000..516fc85
--- /dev/null
+++ b/progs/demo/pfac.hs
@@ -0,0 +1,21 @@
+
+-- This is a parallel varient of factorial
+
+module Main where
+
+fac :: Int -> Int
+fac 0 = 1
+fac n = pfac 1 n
+
+pfac :: Int -> Int -> Int
+pfac low high | low == high = low
+ | low + 1 == high = (low * high)
+ | otherwise = pfac low mid * pfac (mid + 1) high
+ where
+ mid = (high + low) `div` 2
+
+main = appendChan stdout "Type in N: " abort $
+ readChan stdin abort $ \ input ->
+ appendChan stdout (show (fac (read (head (lines input))))) abort done
+
+