Cum scriu bucla while din functia principala, main ?

From HaskellWiki
Revision as of 22:53, 5 January 2008 by Ha$kell (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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  )  
             

{--Reading file "input.hs":
runhugs  myinput.hs
--}