List and Tuples
Haskell have two important data storage
system such as lists and tuples. They are very important thing for
Haskell like functions. Lists are implemented by “[ ]” but
Tuples with “( )”.The differences between lists and tuples are :
#Tuples size is constant but list are
flexible so if we know size of our data we should use tuples for
better performance.
#Tuples can be storage different type
of data like a Truth value and a string can be in same tuples but
list not allow this and return a error which about data types for
example a name and a telephone number can be use in a same tuple but
they cannot be in a list.
In list and tuples we define elements
separating with comas.
list_ex = [1,2,3]
list1_ex = [“ahmet”,”mehmet”,”as”]
tuples_ex = (“john,”,1,True)
main = do
print(list_ex)
print(list1_ex)
print(tuples_ex)
Some mistake coding example
list_ex = [1,”2”,3] – error 1 is
a integer but “2” is a char so types are different
we can add elements into a list with
using “:”.For example;
list_ex[1,2,3]
main = print(0:list_ex)
program will return 0,1,2,3
Hiç yorum yok:
Yorum Gönder