We’re rewarding the question askers & reputations are being recalculated! Read more.

Hot answers tagged

3

It would be more usual to replace the if null strings... conditional with a case, and concat is more commonly used than fold for lists: fizzbuzz :: [Fizzrule] -> Int -> String fizzbuzz rules int = case mapMaybe (processrule int) rules of [] -> show int strings -> concat strings Similarly, processrule would more commonly be written ...


3

getintval is just fromMaybe 1. finder always produces Just - you probably meant to map Nothing to Nothing. finder' is just lookup. foldl (\acc x -> max acc x) 1 is just maximum (so long as ch is never empty). k can be inlined. solve' :: [Char] -> [(Char, Int)] -> Int solve' ch lst = (*length ch) $ maximum $ map (fromMaybe 1 . (`lookup` lst)) ch ...


3

This looks great. Honestly, there isn't anything I'd change. You could make it more pointfree in some parts, but that's not going be more readable or maintainable. Magic numbers The only part I'd change are the static dimensions in main. Those are fine in a toy program, but a proper one will need some kind of configuration, so make sure that you use proper ...


2

I can't comment on performance implications of state monad usage, but it seems like list concatenation may be a bottleneck (e.g. in getTemporalSubformulas or l ++ [time] in update). Minor style notes It is common practice to import Data.Map and Data.Set with alias and to import main type unqualified. This makes type signatures a bit more concise. import ...


1

solutionNaive :: String -> String solutionNaive xs = maximumBy (comparing length) $ map (takeWhileUnique S.empty) $ tails xs where -- Take elements from the list until the first duplicated element is encountered. takeWhileUnique _ [] = [] takeWhileUnique seen (x : xs) = if x `S.member` seen then [] else x : takeWhileUnique xs (x `S....


1

The fmap in labelLeft should be (.). Control.Lens.Zoom provides something like withStateLens. Inline definitions that are only used once. bilabelWith :: Bitraversable t => (l -> indexl -> l') -> (r -> indexr -> r') -> Stream indexl -> Stream indexr -> t l r -> t l' r' bilabelWith f g xs ys = flip ...


Only top voted, non community-wiki answers of a minimum length are eligible