[Haskell-beginners] Help refactor monster function
Dániel Arató
exitconsole at gmail.com
Sun Apr 24 14:41:00 UTC 2016
>> consume f g a = foldl f a . chunk g
>> chunk g = unfoldr (fmap g . (\xs -> if null xs then Nothing else Just xs))
Wow, nice. I figured there must be a better way to express that.
>> gatherRoots = chunk (partition (compare `on` root))
That doesn't typecheck. I think you meant
> gatherRoots = chunk $ \ l@(x:_) -> partition (\y -> root x == root y) l
> P.S. You would be correct in claiming that this rewrite is too distant from
> the original to be of use. My apologies if this is the case.
No, this helps a lot, thanks! Reading pro Haskell like this helps me
improve. It's way more advanced than what I could possibly come up
with though. I'm still working my way through it.
Daniel
More information about the Beginners
mailing list