11 ms·
This isn't exactly true. For example, the article names declaration and assignment as among "statements", but such statements are not first class in Haskell.
by shasta 11y ago
This isn't exactly true. For example, the article names declaration and assignment as among "statements", but such statements are not first class in Haskell. Nor are type, data, type class statements, etc. It is true that Haskell manages to accomplish many things with expressions that you'd use statements for in other languages.
- tel 11y agoAgreed, but there's a pretty straightforward distinction between statements amenable to becoming values and those that aren't. Essentially, those which control and define the type theory are out of scope as well as those which introduce bindings.
- wz1000 11y agoI 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)