Saturday, May 8, 2021

May 2021 1HaskellADay 1Liners: problems and solutions

  • 2021-05-24, Monday:
    Map.partitionWithKey's discriminator is
    p :: k -> a -> Bool
    But I have a function that discriminates only on the key:
    part :: k -> Bool
    write a function that translates my discriminator that can be used by Map.partitionWithKey:
    g :: (k -> Bool) -> (k -> a -> Bool)
    • Social Justice Cleric @noaheasterly:
      g = (const .)
  • 2021-05-09, Sunday:

    THE SEQUEL!

    Okay, kinda the same, ... but not:

    You have: f :: m a
    You want: g :: b -> m b

    Where g runs f, but accepts an argument, b.
    g drops the result of f (... on the floor? idk)
    g returns the argument b lifted to the domain, m

    GO!

    • Denis Stoyanov Ant @xgrommx:
      g (phantom . pure)
      This is just joke)
    • Social Justice Cleric @noaheasterly: (f $>)
  • 2021-05-08, Saturday: two-parter
    1. You have f :: a -> m b
      You want g :: a -> m a

      That is to say: g is a function that returns the input and drops the output of f.

      so:

      blah :: (a -> m b) -> (a -> m a)
    2. What is a gooder name for the blah-function?
    • Jonathan Cast #AJAA #Resist @jonathanccast:
      returnArg = (*>) <$> f <*> return
    • Social Justice Cleric @noaheasterly:
      liftA2 (<*)