On 07/22/2014 05:49 PM, Andrei Alexandrescu wrote:
On 7/21/14, 3:22 PM, Timon Gehr wrote:
On 07/21/2014 06:40 AM, Andrei Alexandrescu wrote:
On 7/20/14, 8:15 PM, Timon Gehr wrote:
On 07/20/2014 10:50 PM, Walter Bright wrote:
...
D has loops, even in pure functions,

So does Haskell.

import Control.Monad
import Control.Monad.ST
import Data.STRef

factorial :: Integer -> Integer
factorial n = runST $ do
   r <- newSTRef 1
   forM_ [1..n] $ \i->
     modifySTRef r (*i)
   readSTRef r

main = print $ factorial 5 -- "120"

And that doesn't look awkward at all :o). -- Andrei


Indeed.

Code sucks. It's its own destruction. -- Andrei


It is easy to understand and works correctly, but of course this is not a canonical implementation of factorial.

Reply via email to