Wednesday, September 2, 2020

September 2020 Haskell Problems and Solutions

Tuesday, September 1, 2020

February 2019 Haskell 1-liners

 

  • February 18th, 2019:
    Define ext :: (Maybe a, b) -> Maybe (a,b)
    e.g.: ext (Just 5, "Hi") = Just (5, "Hi")
    • Al͜l ̸͑ha͂͟il̶! @TechnoEmpress \o/ 
    • cλementd @clementd `fmap swap. sequenceA . swap` :-)
    • Raveline @Raveline bisequence . second pure
    • Alexey Radkov @sheshanaag uncurry (flip $ fmap . flip (,))
    • a fool @fresheyeball ext = \case (Just x, y) -> Just (x, y); _ -> Nothing

September 2020 Haskell 1-liners

  • 2020-09-08: given

    removeInfreqs :: Set String -> Ontology -> Ontology
    removeInfreqs infrequentWords ont = 
       Map.map (\wordcounts -> foldl (flip ri') wordcounts infrequentWords) ont

    where Ontology is a map-of-maps.

    1. remove flip to get the same functional result.
    2. curry away ont from the function removeInfreqs
    3. curry away wordcounts from the map-lambda function.
    4. curry away infrequentWords from the function removeInfreqs

      n.b.: This curry may not be as straightforward as the other curries.

  • 2020-09-01: Given all of the above, and now that you've curried the above lambda to [SPOILER]:

    \key -> const (not (Set.member key stoppers))

    Curry away key from this new lambda.

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