Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
6
Task/Loops-While/Haskell/loops-while-1.hs
Normal file
6
Task/Loops-While/Haskell/loops-while-1.hs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import Control.Monad (when)
|
||||
|
||||
main = loop 1024
|
||||
where loop n = when (n > 0)
|
||||
(do print n
|
||||
loop (n `div` 2))
|
||||
10
Task/Loops-While/Haskell/loops-while-2.hs
Normal file
10
Task/Loops-While/Haskell/loops-while-2.hs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import Data.IORef
|
||||
import Control.Monad.Loops
|
||||
|
||||
main :: IO ()
|
||||
main = do r <- newIORef 1024
|
||||
whileM_ (do n <- readIORef r
|
||||
return (n > 0))
|
||||
(do n <- readIORef r
|
||||
print n
|
||||
modifyIORef r (`div` 2))
|
||||
11
Task/Loops-While/Haskell/loops-while-3.hs
Normal file
11
Task/Loops-While/Haskell/loops-while-3.hs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{-# LANGUAGE MonadComprehensions #-}
|
||||
import Data.IORef
|
||||
import Control.Monad.Loops
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
r <- newIORef 1024
|
||||
whileM_ [n > 0 | n <- readIORef r] $ do
|
||||
n <- readIORef r
|
||||
print n
|
||||
modifyIORef r (`div` 2)
|
||||
Loading…
Add table
Add a link
Reference in a new issue