News for hackers. Stuff that matters.
Re:Confessions of a Ruby Developer Whose Heart was Stolen by... by shangaslammi on Thursday June 13, 2013 @06:18AM (#5873216)
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.

Re:Confessions of a Ruby Developer Whose Heart was Stolen by... by pja on Thursday June 13, 2013 @06:34AM (#5873274)
oo. 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