Friday, April 13, 2018

February 2018 1 Liner 1HaskellADay Problems and Solutions

  • February 8th, 2018: We have maybe :: b -> (a -> b) -> Maybe a -> b. But we don't have list? Or do we? Define list:
    list :: b -> ([a] -> b) -> [a] -> b
    list nullanswer flist lst = undefined
  • BONUS: Both Maybe a and [a] are binary types, ... so is MonadPlus:

    Maybe a = Nothing | Just a
    List a = Cons a (List a) | Nil
    MonadPlus m => mzero | m a `mplus` m a

    Is there some generalization that maybe and list are functions of? What is that generalization?
  • February 6th, 2018:
    You have f :: a -> [b] -> [c]
    But instead of just one a you have [a]
    Define g :: [a] -> [b] -> [c]
    in terms of f
    • Daniel @leptonyu g as bs = foldl (\xs a -> f a bs ++ xs) [] as
    • ptdr_bot @m0rth0n g as bs = flip f bs =<< as
    • Victoria C @ToriconPrime g as bs = concat $ fmap ($ bs) (fmap f as)
    • matt @themattchan g = flip $ concatMap . flip f
    • Nicoλas @BeRewt g = flip (flip (>>=) . flip f) Or: g as bs = as >>= flip f bs
    • Sangeet Kar @sangeet_kar g = foldMap f

Monday, April 2, 2018

March 2018 1HaskellADay problems and solutions