Sort a list of object identifiers: Difference between revisions

Line 133:
 
=={{header|Haskell}}==
<lang Haskell>import Data.List ( sortBysort , intercalate )
 
oid :: [String]
Line 143:
"1.3.6.1.4.1.11150.3.4.0"]
 
splitString :: CharEq a => (a) -> String[a] -> [String[a]]
splitString c [] = []
splitString c s = let ( item , rest ) = break ( == c ) s
( _ , next ) = break ( /= c ) rest
in item : splitString c next
 
convertIntListToString :: [Int] -> String
convertIntListToString list = intercalate "." $. map show list
 
orderOID :: [String]
orderOID = map (\intlist -> convertIntListToString intlist ) $ sortBy. myCriterionsort numberlists.
numberlists = map (\list -> map read $ tail list ) $ map (\myS ->. splitString '.' myS) )$ oid
where
numberlists = map (\list -> map read $ tail list ) $ map (\myS -> splitString '.' myS ) oid
myCriterion :: [Int] -> [Int] -> Ordering
myCriterion a b
|not $ null differences = (\(x,y) -> compare x y ) $ head differences
|otherwise = compare ( length a ) ( length b )
where
differences = filter (\p -> fst p /= snd p ) $ zip a b
 
main :: IO ( )
main = do
mapM_ putStrLn orderOID</lang>
Anonymous user