symbols = ['a'..'c'] --expand s = [c : s | c <- symbols] --expand s = map (\c -> c : s) symbols expand s = map (:s) symbols palindrome s = s == reverse s bfs init expand isGoal = search [init] where search [] = [] search frontiera = let current = head frontiera in (if isGoal current then [current] else []) ++ search (tail frontiera ++ expand current) palindromes = bfs "" expand palindrome lista = ["un", "sir", "ceva", "", "nevid", "", "", "ser"] --nevide = filter (\s -> not (null s)) lista --nevide = filter (\s -> not $ null s) lista --nevide = filter (\s -> not . null $ s) lista nevide = filter (not . null) lista --inc x = x + 1 --inc x = (+1) x inc = (+1) -- definiție point-free --paren s = "(" ++ s ++ ")" --paren s = ("("++) ( (++")") s) paren = ("("++) . (++")") -- definiție point-free - ilizibilă -- Pun în paranteze toate șirurile nevide: --transform lista = map paren (filter (not . null) lista) transform = map paren . filter (not . null) -- Transpusa unei matrice: -- Racket: apply map list M matrix = [[1,2,3], [4,5,6], [7,8,9], [0,1,2]] transpose m = foldr {- (\ row transp -> zipWith (:) row transp ) -} (zipWith (:)) -- definiție point-free (map (\_ -> []) $ head m) m -- alternativ {- (map (:[]) $ last m) $ take (length m - 1) m -} tWith = flip map . filter (not . null) tParen = (`tWith` paren) tPrefix = (`tWith` (">>>"++))