Common roots

Comments

[this is good]
I don't know how efficient it is, but once you have common_prefix_2, you're a simple fold away from common_prefix_n:

common_prefix_2 as bs = map fst . takeWhile (\(a,b)-
Lame; you were right about vox's comment system. No help, no preview, no editing. I'll try again, but this may get eaten as well, since I can't find any instructions on what is and isn't allowed:

common_prefix_2 as bs = map fst . takeWhile (\(a,b)->(a==b)) $ zip as bs
common_prefix = foldr1 common_prefix_2

[this is good]
Of course, fold is the perfect way to generalise a 2 arg function to n-args, thanks!

Post a comment

Already a Vox member? Sign in