Cum scriu bucla while din functia principala, main ?
Jump to navigation
Jump to search
Atunci cand programul principaL PRELUCREAZA UN FLUX DE DATE iar functia principala s-ar fi scris ca o bucla while intr-un limbaj imperativ aveti nevoie de acest while. Este scris in do-notatie si se foloseste de obicei impreuna cu operatii de IO.
while test actiune
= do rezultat <- test
if rezultat then do actiune
while test actiune
else return ()
Exemplu:
module Main where
import IO
-- pentru isEOF
-- isEOF :: IO Bool
while test actiune
= do rezultat <- test
if rezultat then do actiune
while test actiune
else return ()
main= while (do b <- isEOF
return (not b) )
(do s <- getChar
print $ ord s )
{--
runhugs myinput.hs
--}