Software Assurance Reference Dataset

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Tue Jul 22 11:34:20 PDT 2014


On 7/20/2014 8:15 PM, Timon Gehr wrote:
> 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

Would you rather write that or:

   int factorial(int i) pure {
     auto r = 1;
     foreach (i; 1..n + 1)
	r *= i;
     return r;
   }

And I'd love to see what native code is generated for the Haskell example.


More information about the Digitalmars-d mailing list