-- returns a list of maximal sublists s.t. any two consecutive elements of each sublist satisfies a given predicate group :: (a -> a -> Bool) -> [a] -> [[a]] group pred [] = [[]] group pred [a] = [[a]] group pred (a:b:lst) | (pred a b) = ([a] ++ head (group pred (b:lst))):(tail (group pred (b:lst))) | otherwise = [a]:(group pred (b:lst)) ********** Roman numeral converter as follows. Still working on using a RN type rather than just Chars. toRoman x is the "outermost" function, which is basically just a wrapper around toRomanStr, which in turn calls the other functions. -- returns a set of RN symbols representing units, fives and tens given an order of magnitude up from 1 toRomanCharByPos :: Int -> ([Char], [Char], [Char]) toRomanCharByPos 0 = ("I", "V", "X") toRomanCharByPos 1 = ("X", "L", "C") toRomanCharByPos 2 = ("C", "D", "(I)") toRomanCharByPos a = (\(a,b,c) -> ("(" ++ a ++ ")", "(" ++ b ++ ")", "(" ++ c ++ ")")) (toRomanCharByPos (a - 3)) -- returns a RN representation of a single Arabic digit, given a set of symbols to use for units, fives and tens toRomanChars :: Int -> ([Char], [Char], [Char]) -> [Char] toRomanChars 0 (units, fives, tens) = "" toRomanChars 4 (units, fives, tens) = units ++ fives toRomanChars 5 (units, fives, tens) = fives toRomanChars 9 (units, fives, tens) = units ++ tens toRomanChars a (units, fives, tens) = (toRomanChars (a - 1) (units, fives, tens)) ++ units -- returns a RN representation of a "stringified" nonnegative Arabic integer toRomanStr :: [Char] -> [Char] toRomanStr [] = [] toRomanStr (a:as) = (toRomanChars (read [a]::Int) (toRomanCharByPos (length as))) ++ toRomanStr as -- returns a RN representation of an integer toRoman :: Int -> [Char] toRoman a | a < 0 = app ("-", toRoman (-a)) | otherwise = toRomanStr (show a)