4 ms·
It's natural for some operations to be used only for their side effects, and for those a return value is just noise. What does a while loop evaluate to in your
by ezrast 7y ago
It's natural for some operations to be used only for their side effects, and for those a return value is just noise. What does a while loop evaluate to in your favorite language? Are there any circumstances where you'd want to assign one to a variable? What do you lose by making that a parser error?
- uryga 7y ago> What does a while loop evaluate to in your favorite language? depends on what you want! for example this Haskell package¹ defines three versions of while: -- collect the result of each iteration into a list whileM :: Monad m => m Bool -> m a -> m [a] -- combine the result of each iteration together into a final result whileM' :: (Monad m, MonadPlus f) => m Bool -> m a -> m (f a) -- drop the results and return `()` whileM_ :: Monad m => m Bool -> m a -> m () by convention, the ones ending in an underscore (`forM_`, `whileM_`, `sequence_` etc) drop their results, i.e. are only used for their side-effects. ¹ http://hackage.haskell.org/package/monad-loops-0.4.3/docs/Control-Monad-Loops.html http://hackage.haskell.org/package/monad-loops-0.4.3/docs/Co...