home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / MacHaskell 2.2 / progs / demo / pfac.hs < prev    next >
Encoding:
Text File  |  1994-09-27  |  435 b   |  22 lines  |  [TEXT/YHS2]

  1.    
  2. -- This is a parallel varient of factorial
  3.  
  4. module Main where
  5.  
  6. fac :: Int -> Int
  7. fac 0 = 1
  8. fac n = pfac 1 n
  9.  
  10. pfac :: Int -> Int -> Int
  11. pfac low high | low == high     = low
  12.               | low + 1 == high = (low * high)
  13.               | otherwise       = pfac low mid * pfac (mid + 1) high
  14.     where
  15.        mid = (high + low) `div` 2
  16.  
  17. main = putStr "Type in N: " >>
  18.        getLine >>= \ input ->
  19.        putText (fac (read input))
  20.  
  21.  
  22.