Order disjoint list items: Difference between revisions

m
→‎{{header|Haskell}}: (Added an explicit type signature)
m (→‎{{header|Haskell}}: ( Reordering a little to foreground top level ))
m (→‎{{header|Haskell}}: (Added an explicit type signature))
Line 728:
disjointOrder :: Eq a => [a] -> [a] -> [a]
disjointOrder m n = concat $ zipWith (\x y -> x ++ y) ms ns
concat $ zipWith (\x y -> x ++ y) ms ns
 
where
ms = segments m n
Line 736 ⟶ 734:
segments :: Eq a => [a] -> [a] -> [[a]]
segments m n = _m ++ [_acc]
letwhere
(_m, _, _acc) = foldl split ([], n, []) m
split :: Eq a => ([[a]],[a],[a]) -> a -> ([[a]],[a],[a])
split (ms, ns, acc) x
| elem x ns = (ms ++ [acc], delete x ns, [])
| otherwise = (ms, ns, acc ++ [x])
in _m ++ [_acc]
(_m, _, _acc) = foldl split ([], n, []) m
in _m ++ [_acc]
 
-- TEST -----------------------------------------------------------
9,655

edits