Personal tools

La ce folosim operatorul !! (dublu semn de exclamare) ?

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
 
m
Line 12: Line 12:
   
 
Prelude> (!!) [1,2,3,5] 1
 
Prelude> (!!) [1,2,3,5] 1
2
 
   
  +
2
   
 
Prelude> (!!) [1,2,3,5] 2
 
Prelude> (!!) [1,2,3,5] 2
Line 26: Line 26:
   
 
Program error: Prelude.!!: index too large
 
Program error: Prelude.!!: index too large
  +
[http://www.haskell.org/haskellwiki/Ro/Haskell <= Inapoi la pagina principala Ro/Haskell ]

Revision as of 19:39, 5 November 2007

Este folosit pentru a extrage al n-lea element dintr-o lista, n fiind numar intreg.

Aruncati o privire aici:

Prelude> :t (!!)

(!!) :: [a] -> Int -> a

Prelude> (!!) [1,2,3,5] 0

1

Prelude> (!!) [1,2,3,5] 1

2

Prelude> (!!) [1,2,3,5] 2

3

Prelude> (!!) [1,2,3,5] 3

5

Prelude> (!!) [1,2,3,5] 4

Program error: Prelude.!!: index too large <= Inapoi la pagina principala Ro/Haskell