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

Thursday, July 2, 2020

July 2020 1HaskellADay Problems and Solutions


June 2020 1HaskellADay Problems and Solutions

  • YAY! HELLO! Our first #haskell exercise in a while!... and this exercise is about ... wait for it ... exercise
  • For today's #haskell exercise we convert a set of arcs to a graph. #GraphTheory 
  • Thursday, October 17, 2019

    February 2019 1HaskellADay Problems and Solutions

    Monday, February 18, 2019

    April/May 2019 1HaskellADay 1Liners

    • May 27th, 2018:
      data F = F { a, b, c :: String }
      data Stamped a = { time :: Day, stamped :: a }

      f :: Stamped F -> String

      output of f x is  "time a b c" for the respective values of time, a, b, c

      Is there some monadic / applicative elegant definition that does this?
      • Nickolay Kudasov @crazy_fizruk
        f = intercalate “ “ . sequence [ show.time, a.stamped, b.stamped, c.stamped ]
      • Nickolay Kudasov @crazy_fizruk
        f = intercalate " " <$> http://pure.show .time <> (sequence [a, b, c]).stamped
        A bit trickier, but shorter and uses stamped once.
    • April 13th, 2018: given f :: [a] -> b -> [c]
      where c is a derived from g :: a -> b -> c

      You have [a] and [b]

      Write a function h :: [a] -> [b] -> [c] from f

    January 2019 1HaskellADay Problems and Solutions