4 ms·
Cool! Since we're suggesting changes, here's what I'd do. (Not that anything is wrong with the OP's code, just that it's good to point out all the different sty
by wyager 12y ago
Cool! Since we're suggesting changes, here's what I'd do. (Not that anything is wrong with the OP's code, just that it's good to point out all the different stylistic techniques you can adopt.)
7. alphabet = ['a'..'z']
8. nWords = B.readFile "big.txt" >>= return . train . lowerWords . B.unpack
or:
8. nWords = train . lowerWords . B.unpack <$> B.readFile "big.txt"
Make `splits`, `deletes`, etc. values (not functions). `splits` has access to `w`, so there's no need to pass it as an argument 4 times (or even to pass `w` as an argument to the other functions).
27. sortCandidates = (sortBy (flip (comparing snd))) . M.toList
- codygman 12y agoI used to compose return with a series of pure functions as well, but I found that using liftM seems cleaner.
- codygman 12y agoexample: nWords = liftM (train . lowerWords . B.unpack) (B.readFile "big.txt") There was recently a very good article[0] about practically using monads that mentioned using liftM. However whenever using a functor instance is possible it's probably better, since functors can't do as much as monads. I'm not quite sure how much this would help/apply to this small example though. 0: http://softwaresimply.blogspot.com/2014/12/ltmt-part-3-monad-cookbook.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+SoftwareSimply+%28Software+Simply%29 http://softwaresimply.blogspot.com/2014/12/ltmt-part-3-monad...