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

From HaskellWiki
Revision as of 19:38, 5 November 2007 by Ha$kell (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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