4 ms·
I wouldn't call them statements because they aren't executed. Instead, I would classify them as "declarations". You state what something is, instead of telling
by wz1000 11y ago
I wouldn't call them statements because they aren't executed. Instead, I would classify them as "declarations". You state what something is, instead of telling the computer what to do.
Traditional assignment is an expression in Haskell.
count :: Int -> IO Int
count n = do r <- newIORef 0
loop r 1
where
loop :: IORef Int -> Int -> IO Int
loop r i | i>n = readIORef r
| otherwise = do v <- readIORef r
writeIORef r (v+i)
loop r (i+1)