Haskell – czysto funkcyjny język programowania nazwany na cześć Haskella Curry'ego.
Spis treści |
Jego specyficzne cechy to m.in.:
Pliki Haskella mają rozszerzenie
Haskell był początkowo intensywnie rozwijany wokół ośrodka University of Glasgow, popularny kompilator tego języka to Glasgow Haskell Compiler (GHC) kompilujący szybki kod maszynowy porównywalny w szybkości wykonania do kodów z GCC (ok. 1,3 razy wolniejszy niż C).
-- Komentarz silnia 1 = 1silnia n = n*silnia(n-1) silnia' n = product [1..n] fib 0 = 0fib 1 = 1fib n = fib(n-1) + fib(n-2) ack(0,y) = y+1ack(x,0) = ack(x-1,1)ack(x,y) = ack(x-1,ack(x,y-1)) -- przykład użycia strażnikówsign x | x > 0 = 1 | x == 0 = 0 | x < 0 = -1 myproduct [] = 1myproduct (n:m) = n * myproduct m mysum [] = 0mysum (n:m) = n + mysum m data TreeOfMath = Mult TreeOfMath TreeOfMath | Div TreeOfMath TreeOfMath | Add TreeOfMath TreeOfMath | Sub TreeOfMath TreeOfMath | Leaf Float compute (Mult x y) = compute x * compute ycompute (Div x y) = compute x / compute ycompute (Add x y) = compute x + compute ycompute (Sub x y) = compute x - compute ycompute (Leaf x) = x showme (Mult x y) = "(" ++ (showme x) ++ "*" ++ (showme y) ++ ")"showme (Div x y) = "(" ++ (showme x) ++ "/" ++ (showme y) ++ ")"showme (Add x y) = "(" ++ (showme x) ++ "+" ++ (showme y) ++ ")"showme (Sub x y) = "(" ++ (showme x) ++ "-" ++ (showme y) ++ ")"showme (Leaf x) = show x qsort [] = []qsort (x:xs) = qsort less ++ x:(qsort more) where less = [ a | a <- xs, a < x ] more = [ a | a <- xs, a >= x ] -- lista liczb pierwszychprimes = map head $ iterate (\(x:xs) -> [ y | y<-xs, y `mod` x /= 0 ]) [2..] -- lista liczb FibonacciegolistFib = 1:1:(zipWith (+) listFib (tail listFib)) -- wyrażenia TreeOfMath mają postać: (Sub (Mult (Leaf 5) (Leaf 4)) (Add (Leaf 3) (Leaf 2)))
| ||||||||||||||||||||||||||||||||||||||||||||||||||