Software Assurance Reference Dataset

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Sun Jul 20 21:40:25 PDT 2014


On 7/20/14, 8:15 PM, Timon Gehr wrote:
> On 07/20/2014 10:50 PM, Walter Bright wrote:
>> On 7/20/2014 3:27 AM, Dmitry Olshansky wrote:
>>> Functional programming is full of simple recursion and it would be
>>> nice not to
>>> stack overflow in debug builds.
>>
>> Traditional FP languages don't have loops, and so must do recursion.
>
> Uh...
>
>> 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




More information about the Digitalmars-d mailing list