import List ( nub ) import Control.SetFunctions -- Permutation of a list with a functional pattern: perm :: [a] -> [a] perm [] = [] perm (xs ++ y : ys) = y : perm (xs ++ ys) -- Contains a list two elements not in order: someDescending :: [Int] -> Bool someDescending (_ ++ [x,y] ++ _) | x > y = True sort :: [Int] -> [Int] sort xs | isEmpty (set1 someDescending p) = p where p = perm xs -- Compute the length of a list prefix until the first repeated element. lengthUpToRepeat :: [Int] -> Int lengthUpToRepeat (ps ++ [x] ++ _) | nub ps == ps && elem x ps = length ps + 1 example = lengthUpToRepeat [1,2,3,43,99,2,1,3] --> 6