Uploaded by levanfangani55

haskell

advertisement
Lambda
add = \x y -> x + y
Not Lamda:
odds n = map f [0..n-1]
where
f x = x*2 + 1
with lambda:
odds n = map (/x -> x*2 + 1) [0..n-1]
masivis konstruqtori
setfun =[x| <-[100..900],(x`div` 100 + `div` 10 `mod` 10 +x`mod`10)`mod`2==0]
setfun arr =[x| <-arr,(x`div` 100 + `div` 10 `mod` 10 +x`mod`10)`mod`2==0]
same in recursive manner:
setfun :: [Int] -> [Int]
setfun [] = [] -- Base case: empty list
setfun (x:xs)
| isValid x = x : setfun xs -- Add to result if valid
| otherwise = setfun xs -- Skip if not valid
where
isValid x = (x `div` 100 + (x `div` 10) `mod` 10 + x `mod` 10) `mod` 2
== 0
chashenebulebi:
sum[1..10]->jami
product[1..10]->numravli
[1,2,3]++[4,5,6] ->[1,2,3, 4,5,6]
Reverse[1,2]->[2,1]
Zip[1..5] [6..10]-> [(1,6),(2,7),..]
head [1,4,6,3,10] -> 1
tail [1,4,6,3,10] -> [4,6,3,10]
[4,6,3,10]!! 2 ->3 n-uris gamoyofa
take 3 [1,4,6,3,10] ->[1,4,6]
drop 3 [1,4,6,3,10] ->[3,10]
length [1,4,6,3,10] ->5
_________________________________________________________
functions:
f a + b== f(a)+b
f( g x) == f(g(x))
fx (g y) == f(x,g(y))
average arr = sum arr `div` length arr
x `div` y == div x y
aracxadi:
a= b+c
where
cxadi:
b=1
{b=1;
c=2
c=2}
d=a*2
fun x | x >=0 && x/=5 =x/(x-5)
|x ==5
=5
|otherwise
= 4 * x**2
Dunn x = if x >= 0 && x/=5 then x/(x-5)
Else if x== 5 then
Wlse 4* x**2
--($$) True False =False
--($$) _ True = True
--($$) _ _ = True
--($$) True a = a
Recurese:
Factorial 0 =1
Factorial (n+1) =(n+1) * factorial n
Product []= 1
Product ( n:ns) = n* product ns
Length :: [a]->Int
Length []=0
Length(_:xs)= 1 + length xs
Reverse :: [a]->[a]
Reverse[]= 0
Reverse (x:xs) = reverse xs ++ [x]
Zip :: [a] -> [b] ->[(a,b)]
Zip[] _ =[]
Zip _ [] =[]
Zip(x:xs) ( y:ys) =(x,y) : zip xs ys
Download