Difference between revisions of "La ce folosim operatorul !! (dublu semn de exclamare) ?"

From HaskellWiki
Jump to: navigation, search
m (Reverted edits by Tomjaguarpaw (talk) to last revision by Ha$kell)
m (Minor formatting changes)
 
Line 4: Line 4:
 
'''Iata un exemplu de dialog cu interpretorul:'''
 
'''Iata un exemplu de dialog cu interpretorul:'''
   
Prelude> :t (!!)
+
Prelude> :t (!!)
  +
(!!) :: [a] -> Int -> a
   
(!!) :: [a] -> Int -> a
 
 
Prelude> (!!) [1,2,3,5] 0
 
1
   
Prelude> (!!) [1,2,3,5] 0
+
Prelude> (!!) [1,2,3,5] 1
  +
2
   
1
 
  +
Prelude> (!!) [1,2,3,5] 2
 
3
   
Prelude> (!!) [1,2,3,5] 1
+
Prelude> (!!) [1,2,3,5] 3
  +
5
   
2
 
 
Prelude> (!!) [1,2,3,5] 4
 
 
Program error: Prelude.!!: index too large
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
 
   
   

Latest revision as of 23:15, 5 April 2021

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

Iata un exemplu de dialog cu interpretorul:

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



Pagina indexata la indexul Categories:Ro


<= Inapoi la pagina principala Ro/Haskell.

<- Inapoi la Intrebarile incepatorului Ro/Haskell.