RSSAmplifier

Blog

Typed Logic

Incorporates strong typing over predicate logic programming, and, conversely, incorporates predicate logic programming into strongly typed functional languages. The style of predicate logic is from Prolog; the strongly typed functional language is Haskell.

logicaltypes.blogspot.comRSS feed ↗25 posts

Latest posts

November, 2021 1HaskellADay 1Liners

2021-11-09: You have: \k _v -> f k Curry away the arguments. 2021-11-09: Hello, all. It's been a minute. Here's a #1Liner #Haskell problem You have m :: Map a b You want to filter it by s :: Set a so that m has keys only in s. How would you do that? O_O @dysinger: let map = Data.Map.fromList [(1, "one"), (2, "two"), (3, "three")] set = Data.Set.fromList [1,3,5,7,9] in Data.Map.fromList [ elem |…

Why Kleisli Arrows Matter

We're going to take a departure from the style of articles regularly written about the Kleisli category, because, firstly, there aren't articles regularly written about the Kleisli category. That's a loss for the world. Why? I find the Kleisli category so useful that I'm normally programming in the category, and, conversely, I find most code in industry, unaware of this category, is doing a lot of…

June 2021 1HaskellADay Problems and Solutions

Today's #haskell problem: what is 'today' in a data-set . Interesting question. In today's #haskell solution, we build a SQL query , ... WITH HASKELL!

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…

April 2021 1HaskellADay 1Liners Problems and Solutions

2021-04-20, Tuesday: So, I had this problem I have pairs :: [(a, IO [b])] but I want pairs' :: IO [(a, b)] sequence a gives me something like I don't know what: distributing the list monad, not the IO monad. Implement: sequence' :: [(a, IO [b])] -> IO [(a, b)] p h z @phaazon_: fmap join . traverse (\(a, io) -> fmap (map (a,)) io) lucas卞dicioccio, PhD @lucasdicioccio: Just to annoy you I'll use the…

April 2021 1HaskellADay Problems and Solutions

2021-04-28: We build a recommendation-system from spotty data for today's #haskell problem. runRecs rekt the run of the ... rektrun? Bah: today's #haskell solution, with implication to the rescue ! 2021-04-26: Today's #haskell problem, on m̸͈̣̈́̉̉̊̈́y̴̢͌̇̕ ̷̡̗͎̰̠͚̓̈́͠B̷̙͋͊̈̕͘Į̷̻̱͔̼̙͖͚̥̄͝R̴͉̖̻̬̗͕͋̽̉̚͝T̵͈̮͙͚̤̘̦̮͐̓́̔̂͑̋̐̐̄H̶̬̳͔͔̳̀̉̇̋͒D̵̢̡̧̦̖̝͖͕͕̤̊Ȃ̷̧̩̼͔̱͙̟̺̕Y̴̡̢̮̘͛̄̽͛̆̃͌ we solve what every Gubmint…

March 2021 1HaskellADay 1Liners

2021-03-23: You have [a] and (a -> IO b) . You want IO [(a, b)] That is, you want to pair your inputs to their outputs for further processing in the IO-domain. Chris Martin @chris__martin: \as f -> traverse @ [] @ IO (\a -> f a >>= \b -> return (a, b)) as cλementd Children crossing @clementd: traverse (sequenceA . id &&& f) (actually, tranverse (sequence . (id &&& f)) ) Or p traverse (traverse f .…

March 2021 1HaskellADay Problems and Solutions

2021-03-31, Wednesday: Let's go on 50 last dates for today's #haskell problem. Today's #haskell solution shows us the fifty last dates were the fifty best dates . 2021-03-30, Tuesday: Directorizin' ... WITH STYLE! ... is today's #haskell problem. Today's #haskell solution: BEHOLD THE MIGHTY POWER OF THE <*> ! 2021-03-29, Monday: Today's #haskell problem tackles plurality and connectives to list…

February 2021 1HaskellADay Problems and Solutions

2021-02-26: Today's #haskell problem we will be matching the metaphone'd-wineries from wikidata and from the graph-store. Today's #haskell solution gave us 16 good matches from 30 candidates . 2021-02-25: For today's #haskell problem we load the wineries' metaphones to the graph-store . Today's #haskell solution: MWA-HAHA! I HAVE METAPHONES FOR WINERIES ! 2021-02-24: " What's today's date? " is…

January 2021 1HaskellADay 1Liners

2021-01-28: Opposite problem: You have: [(a, Set b)] you want: [(a, b)] e.g.: [("hi", fromList [1,2,3]), ("bye", fromList [4,6,7]) -> [("hi",1),("hi",2),("hi",3),("bye",4),("bye",6),("bye",7)] Interestingly, Set is not a Monad. wut. How do you get around that problem? D Oisín Kidney @oisdk (>>= traverse toList) mine: concatMap (sequence . second Set.toList) 2021-01-28: We have [(Set a, b)] we want…

January 2021 1HaskellADay Problems and Solutions

2021-01-29: Ambitious! Let's upload some indexed wineries with geo-locations to the graph-store for today's #haskell problem! For today's #haskell solution we added geo-locations and wikidata QNames for some wineries , with shout-outs to @oisdk and @tim_1729, incorporating their #1Liner answers into the solution. 2021-01-27: We continue updating our wine-graph with wikidata. Today we update…

December 2020 1HaskellADay Problems and Solutions

2020-12-22: Monads are burritos, but today's #haskell problem brings together the whole enchilada ! In today's #haskell solution we find that whole enchilada is a hot tamale! ... and also map all the air bases of an alliance . 2020-12-21: Collecting the airbases for all the countries of an alliance from the graph-store is today's #haskell exercise. Today's #haskell solution shows how to work with…

November 2020 1HaskellADay 1Liner problems and solutions

In my Data.XHTML library printXML xml = (\elt -> printElementWithOffset elt 0 >> return elt) (rep xml) Curry away the xml -argument to the printXML -function

November 2020 Haskell Problems and Solutions

2020-11-27: Is the morse code table generated from a graph better than by-hand? In today's #haskell problem, WE FIND OUT! 😤 Today's #haskell solution shows I did code the morse table by hand correctly! *whew* and also show how to extract data from a graph-store. And! has Konami's super-secret cheat-code ! ^^vv<><>ba (shh! Don't tell anyone!) 2020-11-25: 'Lorem Ipsum' never looked so good ... IN…

October 2020 Haskell 1-Liners

2020-10-21: Curry `key` from secondPassFilter :: Ord a => a -> Set a -> Maybe b secondPassFilter key = spf key . Set.lookupGE key Given spf :: a -> Maybe a -> Maybe b 2020-10-21: given: updater :: b -> Maybe b and firstPass :: Ord a => Map a b -> Map a b firstPass m = foldr (Map.update updater) m (Map.keys m) #Curry away `m` from the firstPass-function Social Justice Cleric @noaheasterly firstPass…

October 2020 1HaskellADay Problems and Solutions

2020-10-30: Today's #haskell problem is to read and to parse a wikitext file to get a comprehensive list of military alliances. Parsing wikitext of alliances of the world ... WITH #haskell! 2020-10-28: Today's #haskell problem is to ingest military alliances of the world from http://wikidata.org as JSON. The #haskell solution: (*:)-operator and a higher-order alter-function FTW ! 2020-10-26: The…

September 2020 Haskell Problems and Solutions

2020-09-09: Today's #haskell exercise is to compile our book-word-net into a Haskell module. The #haskell solution compiled the August 2020 Gutenberg top 100 read books into Haskell terms. 2020-09-08: Data analytics on our top 100 gutenberg books is today's #haskell exercise. Did you know that there approximately 2000 English words in common usage? Today's #haskell solution: "Sounds about right ."…

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. remove flip to get the same functional result. curry away ont from the function removeInfreqs curry away wordcounts from the map-lambda function. curry away infrequentWords from the…

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…

August 2020 1HaskellADay Problems and Solutions

2020-08-31: For today's #haskell problem we learn the nature of the words "the" and "yesterday." Fundamental things. SCROOGE ! Yesterday's #haskell solution shows us that "scrooge" was the most-written word in "A Christmas Carol." Fancy that! 2020-08-28: Today's #haskell problem: a word-frequency analysis, ... a CLEAN-word-frequency analysis . Today's #haskell solution. Amazing, isn't it, that the…

July 2020 1HaskellADay Problems and Solutions

2020-07-31: Well, that's random . Generating random numbers and sequences is today's #Haskell problem. Today's #haskell solution shows that I can (<*>) that monad, first go , without even looking it up or anything. So, yeah, I'm walking pretty tall right now. 2020-07-30: Kate and Shoaib are going on vacation . Commander Adama in Star Wars tells us that for today's #haskell problem, we are to "Make…

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

February 2019 1HaskellADay Problems and Solutions

February 20th, 2019: Wednesday's #haskell problem: we've got words, now let's find words that start with ... 'x'. February 19th, 2019: Tuesday's #haskell problem: now that we have a word finder, let's pretty-print the results ! February 18th, 2019: Monday's #haskell problem is to come up with sets of words using only a set of supplied letters. Monday's #haskell solution has some trickiness around…

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…