module HigherOrder where
–split into n-size lists and return as list. Return Nothing if not possible
— split 3 [1..9] == Just [ [1,2,3],[4,5,6],[7,8,8] ]
Copyright By PowCoder代写 加微信 powcoder
— split 4 [1..9] == Nothing
— Maybe is in the Prelude and described in Chapter 8.
— do this any way you like
split :: Int -> [a] -> Maybe [[a]]
split n xs = Nothing
–recursively: returns True if list xs can be broken into n-size pieces such
— such that all are the same sequence of values
— use the split function, above, probably
— returns False otheriwse
isRepeats :: Eq a => Int -> [a] -> Bool
isRepeats n xs = False
–use map/filter: otherwise, as above
isRepeats’ :: Eq a => Int -> [a] -> Bool
isRepeats’ n xs = False
–use foldr: otherwise, as above
isRepeats” :: Eq a => Int -> [a] -> Bool
isRepeats” n xs = False
–returns the LONGEST sequence s.t. xs is the concatenation of
— two or more repeats of the sequence (not one… obviously)
— returns Nothing if such a sequence does not exist
— repeats “fred” == Nothing
— repeats “fredfred” == Just “fred”
— repeats [1,2,1,2,1,2,1,2] == Just [1,2,1,2] — NOT [1,2]
repeats :: Eq a => [a] -> Maybe [a]
repeats xs = Nothing
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com