3 ms·
The same thing in Haskell: cycle seq = circular where circular = seq ++ circular (or if you want to really golf it) cycle = fix . (++) Ok, to be fai
by shangaslammi 13y ago
The same thing in Haskell:
cycle seq = circular where circular = seq ++ circular
(or if you want to really golf it)
cycle = fix . (++)
Ok, to be fair the Scala code is a bit more generic as it works for any abstract sequence, but still, Scala's syntax is awfully heavy compared to Haskell.
That's one reason I still prefer Haskell even though Scala is easier to sneak into enterprise projects thanks to JVM. Not to mention that Haskell gives stronger static guarantees and has a more sophisticated type inference system.
- pja 13y agooo. I'd forgotten about fix. cycleM = fix . mplus gives a nice generic version that works on Lists & Sequences but falls afoul of the monomorphism restriction, so it needs a type: cycleM :: (MonadPlus m) => m a -> m a cycleM = fix . mplus