Solution to problem 17 (99 Haskell problems)

Hello, I am wondering, is this solution acceptable to the question 17 ? ( https://www.haskell.org/haskellwiki/99_questions/11_to_20) code: split :: [a] -> Int -> ([a], [a]) split xs y = fst (mapAccumL (\a b -> (let f = fst a s = snd a l = length f in if l < y then (f ++ [b], s) else (f, s ++ [b]), b)) ([],[]) xs) Also, any inputs are welcome (indentation, misuse of something) Best regards, Jean Lopes

On Mon, Dec 08 2014, jean lopes
Hello, I am wondering, is this solution acceptable to the question 17 ? ( https://www.haskell.org/haskellwiki/99_questions/11_to_20)
code: split :: [a] -> Int -> ([a], [a]) split xs y = fst (mapAccumL (\a b -> (let f = fst a s = snd a l = length f in if l < y then (f ++ [b], s) else (f, s ++ [b]), b)) ([],[]) xs)
The example worked for me, so yes! It's a bit hard to read, though. Stylistically, I would move the the let expressions into a where block for readability. That would open up a few other pattern matching opportunities. e.g. split :: [a] -> Int -> ([a], [a]) split xs y = fst (mapAccumL go ([],[]) xs) where go (f,s) b = if length f < y then ((f ++ [b], s), b) else ((f, s ++ [b]), b) Cheers, -Christopher
Also, any inputs are welcome (indentation, misuse of something)
Best regards, Jean Lopes _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- Christopher Reichert irc: creichert gpg: C81D 18C8 862A 3618 1376 FFA5 6BFC A992 9955 929B
participants (2)
-
Christopher Reichert
-
jean lopes