Personal tools

Sunt variabilele din do-notatie variabile globale ?

From HaskellWiki

Revision as of 13:45, 13 April 2011 by Ha$kell (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

[Category:Ro]

Sunt variabilele din do-notatie variabile globale ?

Raspunsulk este: Nu. Sunt niste denumiri care se leaga cu niste valori, ca toate variabilele din Haskell. Si nu sunt globale. Sunt mai curand locale secventelor do { ...} care le contin. Scrieti de exemplu programul:

main :: IO ()
main = do { x <- return '1' ;
            putChar x;
            do { x <- return '2' ;
                 putChar x;
                 return ();
                } ;
            putChar x;       
            return () 
          }

Salvati fiserul sub un nume ca : test.hs

Si rulati cu ghci sau cu Hugs:

hugs test.hs

{--
dan@device:~$ hugs test.hs
__   __ __  __  ____   ___      _________________________________________
||   || ||  || ||  || ||__      Hugs 98: Based on the Haskell 98 standard
||___|| ||__|| ||__||  __||     Copyright (c) 1994-2005
||---||         ___||           World Wide Web: http://haskell.org/hugs
||   ||                         Bugs: http://hackage.haskell.org/trac/hugs
||   || Version: September 2006 _________________________________________
 
Haskell 98 mode: Restart with command line option -98 to enable extensions
 
Type :? for help
Main> main
121
 
--}

De altfel Haskell, limbaj functional pur, nu are variabile globale. E vorba de acele variabile care modificandu-se ca urmare a unor instructiuni gresite dau atatea probleme la depanare.