Wednesday, August 26, 2020

August 2020 1HaskellADay 1Liners

  • 2020-08-31:

    #Haskell #BetterWithCurry #1Liner For:
    >>> :t Map.filterWithKey 
    Map.filterWithKey :: (k -> a -> Bool) -> Map k a -> Map k a

    we have this filtering function: \key _val -> not (Set.member key stoppers)

    _val is unused. Curry it away.

  • 2020-08-28: 
    rmFront :: Set Char -> String -> String
    rmFront weirds str = dropWhile (flip Set.member weirds) str
    Simple currying questions: can this function-implementation be simplified with currying? Can it be simplified ... MORE? Answers: yes, and yes. Show your implementation.

  • 2020-08-26: We have this: \info -> importBook info >>= return . (info,) There are way too many info-references. What's a better way to write this expression?
    • Five solutions from @noaheasterly:
      • runKleisli (id &&& Kleisli importBook)
      • liftA2 (liftA2 (,)) return importBook
      • liftA2 (fmap . (,)) id importBook
      • traverse importBook . join (,)
      • traverse importBook . (id &&& id)

Monday, August 3, 2020

August 2020 1HaskellADay Problems and Solutions