# Functii din Prelude, A-F

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

abs - valoarea absoluta

all - predicatul e adev pe toata lista de argumente

and - conjunctie generalizta pe o lista de valori de tip Bool

any - exista o valoare pe lista care satisface predicatul (in engleza aceste intrebari se pun cu any)

atan - arctangenta

break - rupe o lista inaintea locului/elementului care satisface un predicat

ceiling - rotunjirea superioara la un intreg

chr - caracterul cu acel cod ascii

concat - concatenarea unui grup deliste , dat ca lista :)

cos - cosinusul

digitToInt - transforma caracterul cifra in valoarea lui

div - impartirea intreaga

drop - arunca primele dintr-o lista

dropWhile - arunca primele care indeplinesc conditia

```         -- folositor la a  ajunge la primele elemente semnificative daca pui conditia invers
```

elem - apartine listei

error - genereaza eroare si poate avea orice tip, folositi-o deci oriunde exp - e(x)

flip - schimba ordinea argumentelor unei functii cu doua arg

filter - alege ce satisface predicatul, din lista data

```
:t abs
abs :: Num a => a -> a

Prelude> abs -9
ERROR - Illegal Haskell 98 class constraint in inferred type
*** Expression : abs - 9
*** Type       : (Num a, Num (a -> a)) => a -> a

Prelude> abs (-9)
9
Prelude> abs (-9.3)
9.3
Prelude>
----
Prelude> :t all
all :: (a -> Bool) -> [a] -> Bool
Prelude> all isDigit "12234678"
True
Prelude> all isDigit "danu"
False
Prelude>
----
lse
Prelude> :t and
and :: [Bool] -> Bool
Prelude> and [True,True ,True]
True
Prelude> and [True,True ,True,False]
False
Prelude>
----
Prelude> :t atan
atan :: Floating a => a -> a
Prelude>
Prelude> 4  * atan 1
3.14159
----
relude> :t break
break :: (a -> Bool) -> [a] -> ([a],[a])
Prelude> break isDigit "R2D2"
("R","2D2")
Prelude> break isDigit "3PO"
("","3PO")
Prelude>
Prelude> break isSpace "La Multi Ani 2008!"
("La"," Multi Ani 2008!")
Prelude>
Prelude> break (==0) [5,24,23,2,1,0,-1]
([5,24,23,2,1],[0,-1])
Prelude>
----
Prelude> :t ceiling
ceiling :: (RealFrac a, Integral b) => a -> b
Prelude> ceiling 2.2
3
Prelude> ceiling 1.242
2
Prelude> ceiling 1.42
2
Prelude>
----
Prelude> :t chr
chr :: Int -> Char

Prelude> chr 66
'B'
Prelude> chr 65
'A'
Prelude> chr 32
' '
Prelude>
----
Prelude> :t concat
concat :: [[a]] -> [a]
Prelude> concat ["La", "Multi", "Ani","!"]
"LaMultiAni!"
Prelude>
----
Prelude> :t cos
cos :: Floating a => a -> a
Prelude> cos 0
1.0
Prelude>
----
relude> digitToInt "0"
ERROR - Type error in application
*** Expression     : digitToInt "0"
*** Term           : "0"
*** Type           : String
*** Does not match : Char

Prelude> digitToInt '0'
0
Prelude> digitToInt '1'
1
Prelude> digitToInt '2'
2
Prelude> digitToInt '3'
3
Prelude> digitToInt '4'
4
Prelude> digitToInt 'u'

Program error: Char.digitToInt: not a digit

Prelude>
----
Prelude> :t div
div :: Integral a => a -> a -> a
Prelude> 10 `div` 3
3
Prelude>
----
Prelude> :t drop
drop :: Int -> [a] -> [a]
Prelude> drop 2  ["La", "Multi", "Ani","!"]
["Ani","!"]
Prelude>
-----
Prelude> :t dropWhile
dropWhile :: (a -> Bool) -> [a] -> [a]
Prelude> dropWhile  (==0) [0,0,0,0,1,2,3,4,0,0,1,2]
[1,2,3,4,0,0,1,2]
Prelude>
Prelude> :t elem
elem :: Eq a => a -> [a] -> Bool
Prelude> elem "!"   ["La", "Multi", "Ani","!"]
True
Prelude> elem "2008"   ["La", "Multi", "Ani","!"]
False
Prelude> elem "2000"   ["La", "Multi", "Ani","!"]
False
Prelude>
----
Prelude> :t error
error :: String -> a
Prelude> error "Stop the train!"
ERROR - Cannot find "show" function for:
*** Expression : error "Stop the train!"
*** Of type    : a

Prelude> error "Stop the train!" :Char
ERROR - Undefined constructor function "Char"
Prelude> error "Stop the train!" :: String
"
Program error: Stop the train!

Prelude>
----
Prelude> :t exp
exp :: Floating a => a -> a
Prelude> exp 1
2.71828
Prelude>
----
Prelude> :t flip
flip :: (a -> b -> c) -> b -> a -> c
Prelude> (flip (>)) 1 2
True
Prelude>
----
Prelude> :t filter
filter :: (a -> Bool) -> [a] -> [a]
Prelude> filter (>2) [1,2,3,4,1]
[3,4]
Prelude>```