import Control.SetFunctions import Data.List (nub) idpair :: a -> (a,a) idpair x = (x,x) f :: (Int,Int) -> Int f (idpair x) = 0 -- <=> --f (x,x) = 0 <=> --f (x,y) | x=:=y = 0 zero :: Int -> Int zero _ = 0 pair :: Int -> Int -> (Int,Int) pair x y = (x,y) g :: (Int,Int) -> Int g (pair (zero x) x) = 0 -- > g (0,x) = 0 ------------------------------------------------------------- -- Permutation with functional patterns: perm :: Data a => [a] -> [a] perm [] = [] perm (xs ++ x : ys) = x : perm (xs ++ ys) -- Contains a list two adjacent element out of order: someDescending :: [Int] -> Bool someDescending (_ ++ [x,y] ++ _) | x > y = True -- A new permutation sort: sort :: [Int] -> [Int] sort xs | isEmpty ((set1 someDescending) p) = p where p = perm xs -- Returns the length of the input list until the first repeated element. lengthUpToRepeat :: [Int] -> Int -- lengthUpToRepeat [1,2,5,42,41,4,2,5,6] --> 7 lengthUpToRepeat (ps ++ [r] ++ _) | r `elem` ps && nub ps == ps = length ps + 1