-- wyrażenia TreeOfMath mają postać: (Sub (Mult (Leaf 5) (Leaf 4)) (Add (Leaf 3) (Leaf 2))) data TreeOfMath = Mult TreeOfMath TreeOfMath | Div TreeOfMath TreeOfMath | Add TreeOfMath TreeOfMath | Sub TreeOfMath TreeOfMath | Leaf Float
compute (Mult x y) = compute x * compute y compute (Div x y) = compute x / compute y compute (Add x y) = compute x + compute y compute (Sub x y) = compute x - compute y compute (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 pierwszych primes = map head $ iterate (\(x:xs) -> [ y | y<-xs, y 'mod' x /= 0 ]) [2..]
-- lista liczb Fibonacciego listFib = 1:1:(zipWith (+) listFib (tail listFib))
Przypisy
Linki zewnętrzne
Strona domowa Haskella Wiki poświęcona Haskellowi
Kategoria:Języki funkcyjne