Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Haskell
Wiki community
Recent changes
Random page
HaskellWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Ce inseamna lazy evaluation ?
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==. Un caz ne va arata deosebirile == Sa presupunem ca scriem un spreadsheet / o foaie de calcul / un program de calcul tabelar. Imaginati-va o tabla de sah pe care in loc de piese stau atribuiri care depind unele de altele. Pe vremea cand se lucra in limbajele imperative, C Pascal samd, a programa un spreadsheet era o treaba grea. De exemplu, pe tabla puteau fi urmatoarele calcule de facut: <haskell> a1=1 a3=a4+b5 a4=a2+1 a2=b5+2 b5=a1+3 </haskell> Nici macar un interpretor, de Pascal sau C, sau Basic in ciuda interactivitatii sale nu putea rula asa ceva. Incercati! Pentru a programa un spreadsheet trebuia sa implementezi niste algoritmi din teoria grafurilor care verificau daca nu erau cicluri in grafuri si calculau valorile in ordinea NECESARA. Din cauza aceasata un program de calcul tabelar era un software complicat si scump, iar autorul programului LOTUS 1 2 3, un student ca si voi, s-a umplut de bani din vanzarea acestuia. Ei bine, in Haskell, programul de mai sus este un program perfect valabil, ceea ce inseamna ca este suficient sa parcurgeti matricea spreadsheet-ului si sa print-ati in forma de program Haskell calculele din celulele cu formule. Haskell include exact mecanismul care lipseste din Basic, Pascal si C, si alege dinamic ordinea in care sa '''proceseze''' declaratiile, astfel ca poate calcula totul. Salvati codul de mai sus intr-un fisier : ''lazy.hs'' si apoi: hugs lazy.hs Obtineti un program care ruleaza perfect :)) <haskell> dan@device:~$ hugs lazy.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> a1 1 Main> a2 6 Main> a3 11 Main> a4 7 Main> b5 4 </haskell> Este aproape ca si cum am spune ca in Haskell putem lucra cu valori definite in viitor, bineinteles cu conditia ca sa nu se formeze cicluri in graful dependentelor. Declaratiile pot fi scrise in orice ordine ! Mai programati in Pascal, C sau Java ? Iar daca da, ati inteles acum ce limitari au ? ---- Dan P 10 aprilie 2011
Summary:
Please note that all contributions to HaskellWiki are considered to be released under simple permissive license (see
HaskellWiki:Copyrights
for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel
Editing help
(opens in new window)
Toggle limited content width