Skip to content

Instantly share code, notes, and snippets.

View matoous's full-sized avatar

Matouš Dzivjak matoous

View GitHub Profile
permutate :: (Eq a) => [a] -> [[a]]
permutate [] = [[]]
permutate l = [a:x | a <- l, x <- permutate $ filter (\x -> x /= a) l]
-- 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