{-# LANGUAGE FlexibleInstances #-} module Main where import Data.List {- haskell.org/hoogle lleksah Изучай Haskell ради добра -} -- Show Read Num Integral Eq Ord type ListInt = [Integer] class Insertable a where ins :: Int -> a -> a data Color = Red | Blue | Green data Tree = Empty | Tree Int Tree Tree deriving (Show, Eq, Read) elems :: Tree -> [Int] elems (Empty) = [] elems (Tree x l r) = elems l ++ [x] ++ elems r instance Insertable Tree where ins x Empty = Tree x Empty Empty ins x t@(Tree y l r) = case compare x y of LT -> Tree y (ins x l) r GT -> Tree y l (ins x r) EQ -> t {-instance Show Tree where show Empty = "Empty" show (Tree x l r) = "Tree " ++ show x ++ " (" ++ show l ++ ") (" ++ show r ++ ")"-} instance Insertable [Int] where ins x xs = x : xs main = interact solve solve :: String -> String solve content = error "asdfafg" --show $ Tree 5 Empty Empty == ins 5 Empty --ins 4 (Tree 5 (Tree 3 (Empty) (Empty)) (Empty)) qsort [] = [] qsort xs = let key = xs !! k k = length xs `div` 2 left = filter (< key) xs right = filter (> key) xs middle = filter (== key) xs in qsort left ++ middle ++ qsort right --qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs) fib = 0 : 1 : zipWith (+) fib (tail fib) fib 0 = fib 1 = fib n | n < 0 = error "" myReverse :: [a] -> [a] myReverse = myReverse' [] myReverse' result [] = result myReverse' result (x : xs) = myReverse' (x : result) xs myReverse1 :: [a] -> [a] myReverse1 = foldl (\xs x -> x : xs) []