samedi 18 juillet 2015

Is using long where statements bad coding style?

I am a Haskell newbie, so I don't know a lot about the coding style. I have a function that chains a lot of random generators. Is this kind of code considered in bad style, wherein I have ~10 lines after a where statement? If so, what are the alternatives?

#!/usr/bin/env runhaskell
{-# LANGUAGE UnicodeSyntax #-}
module Main where

makeDummy :: RandomGen g ⇒ [String] → FilePath → g → (FilePath, g)
makeDummy words root gen0 = (fullPath, gen7)
  where
      (numWordsInTitle, gen1) = randomR (1 :: Int, 4 :: Int) gen0 -- unused
      (title, gen2) = randomChoice words gen1
      (year, gen3) = randomR (1800 :: Int, 2100 :: Int) gen2
      (resNum, gen4) = randomChoice ["1080", "720", "480"] gen3
      (resLetter, gen5) = randomChoice ["P", "p", "i", "I"] gen4
      res = resNum ++ resLetter
      (shuffled, gen6) = shuffle [title, show year, resNum ++ resLetter] gen5
      (fileExt, gen7) = randomChoice [".mkv", ".mp4", ".ogv", ".srt", ""] gen6
      path = (++ fileExt) $ intercalate " " shuffled
      fullPath = root </> path

As this could be a somewhat subjective subject, please restrain answers to relfect the Haskell community code style norms, rather than personal opinion/aesthetics.




Aucun commentaire:

Enregistrer un commentaire