Man or boy test: Difference between revisions
m
→{{header|Haskell}}: Pruned leading spaces, applied hindent, traded liftM2 for liftA2, added type signatures, qualified imports.
(added Ol) |
m (→{{header|Haskell}}: Pruned leading spaces, applied hindent, traded liftM2 for liftA2, added type signatures, qualified imports.) |
||
Line 1,771:
Haskell is a pure language, so the impure effects of updating ''k'' must be wrapped in the IO or ST [[Monads|monad]]:
<lang haskell>
a
a k x1 x2 x3 x4 x5 = do r <- newIORef k▼
:: (Enum a, Num b, Num a, Ord a)
let b = do k <- pred !r▼
=> a -> IO b -> IO b -> IO b -> IO b -> IO b ->
r <- newIORef k
where f !r = modifyIORef r f >> readIORef r▼
let b = do
a k b x1 x2 x3 x4
if k <= 0
then liftA2 (+) x4 x5
else b
where
main :: IO ()
main = a 10 #
where
( # ) f = f . return</lang>
On an AMD Opteron 6282 SE using GHC 7.8.2 this program can compute ''k'' = 30 in 1064 s and 156.2 GiB.
|