News for hackers. Stuff that matters.
Re:Why functional programming matters (1990) [pdf] by tel on Thursday May 07, 2015 @01:34PM (#9506801)
This is a regionalized or "benign" effect. To the degree that this can be proven in Haskell's synthetic effect calculus it's OK. Since Haskell does have `unsafePerformIO` we can, with great care, introduce new rules to the type system. This is how `ST` was created

    -- we need a primitive first
    while :: Monad m => m Bool -> m a -> m ()
    while conde bodye = do
      cond <- conde
      if cond then bodye else return ()

    -- then we can make a direct, verified pure translation
    f :: a -> Int
    f x = runST $ do
      i <- newSTRef 17
      while (readSTRef i >>= \ival -> return (ival > 0)) $ do
        modifySTRef i (\ival -> ival - 1)
      ival <- readSTRef i
      return ival
Re:Why functional programming matters (1990) [pdf] by dllthomas on Thursday May 07, 2015 @04:20PM (#9507982)
I think your "while" is "when".
Re:Why functional programming matters (1990) [pdf] by tel on Thursday May 07, 2015 @05:54PM (#9508590)
Oh, thanks! Good catch. Here's `while`

    while :: Monad m => m Bool -> m a -> m ()
    while conde bodye = do
      cond <- conde
      if cond then bodye >> while conde bodye else return ()