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