This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
permutate :: (Eq a) => [a] -> [[a]] | |
permutate [] = [[]] | |
permutate l = [a:x | a <- l, x <- permutate $ filter (\x -> x /= a) l] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Haskell suffix calculator (Polish notation) | |
import Data.List | |
suffixCalc :: (Num a, Read a) => String -> a | |
-- other option is to write this: | |
-- suffixCalc x = head $ foldl calcFun [] $ words x | |
suffixCalc = head . foldl calcFun [] . words | |
where | |
calcFun (a:b:bs) "+" = (a + b):bs | |
calcFun (a:b:bs) "-" = (b - a):bs |
NewerOlder