- December 29th, 2017:
given f :: Monad m => n -> a -> m (Maybe b)
define g :: Monad m => n -> a -> m (a, Maybe b)
using f and ... arrows? Kleisli category? - Bazzargh @bazzargh (\n a->liftM ((,) a) (f n a)) ... according to pointfree.io, that's `liftM2 fmap (,) . f` but I can't pretend to get the transformation
- December 29th, 2017:
given f :: a -> b
define g :: [a] -> [Maybe c] -> [(b, c)]
>>> g [1,2,3] [Just 7, Nothing, Just 10]
[("1",7),("3",10)]
when f = show - matt @themattchan
g = catMaybes ... zipWith (fmap . (,) . f)
where (...) = (.).(.) - garrison @GarrisonLJ g a b = map (f.id***fromJust) . filter (isJust . snd) $ zip a b
- TJ Takei @karoyakani g = (catMaybes .) . zipWith ((<$>) . (,) . f)
- December 29th, 2017: define f :: [(a,b)] -> ([a], [b])
- Андреев Кирилл @nonaem00 and matt @themattchan unzip
- Victoria C @ToriconPrime f = fmap fst &&& fmap snd
- (in a vacuum, a more general type signature would be inferred, but the compiler limits itself as instruct)
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.
Friday, January 5, 2018
December 2017 1HaskellADay 1Liners problems and solutions
Tuesday, January 2, 2018
December 2017 1HaskellADay problems and solutions
- December 29th, 2017: In Friday's #haskell problem we leave 2017 with a filter and a BANG! ... BANG! Today's #haskell solution we weave logging into the ETL article upload process.
- December 28th, 2017: Thursday's #haskell problem is late AND a quicky: fetch a row of JSON from the database and pretty-print it. Thursday's #haskell solution had me leap from the bath tub and shout EUREKA! as I saw the issue in the JSON.
- December 27th, 2017: In Wednesday's #haskell problem we learn that when you parse dates for your articles, you don't need to carbon-date it anymore. In the solution to yesterday's #haskell problem, we encounter and report some parsing issues around optionality.
- December 26th, 2017: Tuesday's #haskell problem: scan an article archive, store an article archive; databases are neat that way. Today's #haskell solution: storing articles-as-JSON into a PostgreSQL database? No problem!
- December 22nd, 2017: Friday's #haskell exercise we do our first bit of parsing with the help of tagsoup. Okay, this #haskell Aeson / TagSoup stuff is awesome for parsing JSON / HTML stuff.
- December 20th, 2017: Wednesday's #haskell exercise. We take a large-ish JSON article archive, scan it, and spit out* a smaller-...ish JSON article archive. *'spit out' is a technical term. Today's #haskell solution provides a subset of the JSON article archive printed prettily.
- December 18th, 2017: Monday's #haskell problem: Friday you submitted an oembed request for goats, today you create a JSON oembed response service. Today's #haskell solution brings you a goat oembed service, serve with PHP.
- December 15th, 2017: Today we build a goat oembed request. I kid you not! geddit? GEDDIT? Today's #haskell solution: OEmbed Goats requests, want? OEmbed Goats requests, GOT!
- December 14th, 2017: Thursday's #haskell problem we sing 🎵 ... EVERYBODY'S WORKIN' FOR THE WEEKEND! 🎶 So, 18 composeable dates on the weekends. I'm freeing up my calendar, then!
- December 13th, 2017: Wednesday's #haskell problem is a hot date! WOOT! Today's #haskell solution has 66 composable dates in 2017. Cool!
- December 12th, 2017: Tuesday's #haskell problem is batching a SQL queryinstead of making multiple queries. It is so much faster! Today's #haskell solution has another LEFT JOIN in the SQL query to consolidate data gathering.
- December 11th, 2017: Monday's #haskell problem is computing and storing exponential distribution values. The exponential distribution: today's #haskell solution shows it's really simple.
- December 8th, 2017: For Friday's #haskell problem we parse NYT article summaries and upload them to a PostgreSQL database. Today's #haskell solution shows that our simple parsing exercise wasn't so simple. Isn't dirty data delightful?
- December 7th, 2017: Throwing the switch with Thursday's #haskell with a hard reset of the database. For today's #haskell solution we do a hard reset: we wipe the recommendation and publish tables and repopulate.
- December 6th, 2017: It's 'kinda' bad to return articles from a search that are already recommended. Wednesday's #haskell problem fixes this. Today's #haskell solution shows what a simple filter notMember can do.
- December 5th, 2017: Tuesday's #haskell problem we narrow our focus and structure our keyword search-space only on keys requested in the NYT archive on PostgreSQL. With a little bit of monadic/applicative magic, we have narrowed keyword searches.
- December 4th, 2017: For Monday's #haskell problem: "But can Haskell do anything useful?" Two words: ... yes.
- December 1st, 2017: For Friday's #haskell problem, what happens when the boss says: "That's good, but ..."? REWORK! THAT's what happens! Today's #haskell solution renders the source article in full and the recommended articles in brief. Got it!
Friday, December 29, 2017
November 2017 1HaskellADay 1Liner problem and solutions
- November 5th, 2017: f :: Map Int [a] -> [b] - > [(Int, b)]
for, e.g.: f mapping bs
length bs == length (concat (Map.elems mapping))
define f - Andreas Källberg @Anka213 Using parallel list comprehensions:
f mp bs = [ (k,b) | (k,as) <-assocs mp, a <- as | b <- bs] - Steve Trout @strout f = zip . foldMapWithKey (fmap . const)
Thursday, November 30, 2017
November 2017 1HaskellADay problems and solutions
- November 30th, 2017: For Thursday's #haskell problem we've published our articles to the PostgreSQL database, now let's extract them as JSON. Today's #haskell solution is a simple SQL query and applying some work from previous exercise to fetch and JSONify recommended articles to print!
- November 29th, 2017: For Wednesday's #haskell problem, now that we've selected the recommended articles, let's save that for review to the PostgreSQL database. For today's #haskell solution, we delete the old recommendations-to-be-published, we insert the new set. Voilà!
- November 28th, 2017: Monday we added articles from a PostgreSQL database using #haskell; Tuesday we delete articles. WHEEEEE! Today's #haskell solution shows that deleting article recommendations is very much like adding recommendations, ... in reverse. WHODATHUNK!
- November 27th, 2017: Monday's problem: "It's not rocket science!" Adding articles to a recommendation set in PostgreSQL with #haskell. A little bit of #haskell; a little bit of #PHP and we have an article-adder-webservice ... thingie!
- November 24th, 2017: Friday's #haskell problem: PostgreSQL database, JSON, Haskell: you've got yourself a webservice. Friday's #haskell solution uses the Brief-structure, this time to show article recommendations.
- November 23rd, 2017: For Thursday, a fun little #haskell JSON-y exercise on Thanksgiving Day from the USA to you! Y'know, Nietzsche says: "Out of chaos comes JSON." ... no ... wait.
- November 22nd, 2017: Wednesday's #haskell problem: given a NYT article index, extract the article full text from PostgreSQL. Simple, eh? ... 'maybe.' Full text of NYT articles archived in PostgreSQL as JSON.
- November 21st, 2017: Tuesday's #haskell problem we slim down the article JSON returned from yesterday by providing article briefs. Today's #haskell solution goes from a set of recommendations from NYT articles to briefs.
- November 20th, 2017: Monday's #haskell problem moves keyword/key-phrase-article retrieval and matching to the PostgreSQL database. Today's #haskell solution: we build our keyword-key-phrase dictionary from SQL and filter articles indexing from those keywords.
- November 17th, 2017: Thursday we linked keywords to key-phrases; for Friday's #haskell problem, we'll upload that linkage information to a PostgreSQL data store. Today's #haskell solution stores 26,000+ keywords, with almost 240,000 cross-references into nearly 10,000 NYT articles. Whoa.
- November 16th, 2017: Thursday's #haskell problem: provide a mapping from unique keywords to key-phrases containing them. Mapping keywords to key-phrases, it's what we do for today's #haskell solution.
- November 15th, 2017: Wednesday's #haskell problem is to parse a CSV file of articles to upload to an article MongoDB. Today's #haskell solution has a little bit of CSVing and a little bit of JSONification to upload article information into MongoDB.
- November 14th, 2017: Tuesday's #haskell exercise is a parsing exercise of a different sort: parsing CSV, but with embedded quote within columns! Ooh! We now can parse CSV files with embedded quotes. YES! Adding that to the old CSV parsing library.
- November 13th, 2017: Indexing articles by keyword and then searching articles by keyword for Monday's #haskell problem. For today's #haskell solution we intersect sets of articles to do fast keyword searches.
- November 10th, 2017: Friday's #haskell exercise is to load the keywords and recommended articles into the PostgreSQL database. Thanks to today's #haskell solution we have articles and keyphrases indexed by keyword.
- November 9th, 2017: Thursday's #haskell problem ties NYT article data stored in PostgreSQL together with the recommended articles from JSON. Today's #haskell solution is reading NYT article recommendations from a PostgreSQL database.
- November 8th, 2017: Wednesday's #haskell problem is to combine article recommendations with their key-phrases to output as JSON. Wednesday's #haskell solution: JSON: GET. (p.s. I love Data.Aeson.Encode.Pretty)
- November 7th, 2017: Tuesday's #haskell problem is to parse JSON of NYT articles and their metadata. Today's #haskell solution: we have articles stored as JSON, and, voilà! we materialize those articles!
- November 6th, 2017: Monday's #haskell exercise is to parse a CSV file of recommended articles from the NYT archive. Today's #haskell solution uses the reads-function to guide the parsing of values from a CSV file.
- November 3rd, 2017: Today is Friday! YAY! Do you know what that means? It's PARSING DAY is #haskell-land! YAY! ... no ... wait. What? TIL that parsing keywords and parsing LISTS of keywords can be very different things for today's #haskell solution.
- November 2nd, 2017: Today's #haskell problem: 'Hello, world' in Haskell. Snark on the side FO' FREE! I don't recall Eliza being this snarky, but today's #haskell solution says differently.
- November 1st, 2017: Wednesday #haskell problem is scan a new archive and update the special character file or correct the new archive. The #haskell solution to replacing special characters... WHAT special characters? They GONE! #ETL
Saturday, November 4, 2017
October 2017 1Liner 1HaskellADay problems and solutions
- October 20th, 2017:
You have a list of numbers: [1,2,3,4]
You have a list of the same length of number fns: [succ, id, id, succ]
You want: [2,2,3,5] - 🇪🇺 Cλément D 🌈 🐇 @clementd zipWith (flip ($)) ?
- he adds: `zipWith (flip id)` is a bit shorter tho
- Simon Courtenage @SCourtenage zipWith ($) [succ,id,id,succ] [1,2,3,4]
- lukasz @lukaszklekot getZipList $ ZipList [succ, id, id, succ] <*> ZipList [1, 2, 3, 4]
- Alexey Radkov @sheshanaag (map (uncurry ($)) .) . zip
- October 5th, 2017: "reverse the sequencing"
You have [[(1,2),(1,3),(1,7)],[(9,2)],[(11,3)]]
You want [(1,[2,3,7]),(9,[2]),(11,[3])] - bazzargh @bazzargh map ((,) <$> head.(map fst) <*> (map snd))
- bazzargh @bazzargh map ((first head).unzip)
- Chris Martin @chris__martin \x -> [(a, b : fmap snd xs) | Just ((a, b) :| xs) <- fmap="" li="" nonempty="" x="">->
- Simon Courtenage @SCourtenage fmap (\x -> (fst . head $ x, fmap snd x))
- Denis Stoyanov 🐜 @xgrommx Your solution nice) but u can do it with point free style like
- fmap(fst.head &&& fmap snd)
- Denis Stoyanov 🐜 @xgrommx My solution is ugly, but I wanna to solve it with traverse)
- fmap(first head . traverse (first (:[])))
- Andreas Källberg @Anka213 map$fst.head&&&map snd
- Scott Fleischma @scottfleischman
traverse
$ _1
(\case
[y] -> Just y
_ -> Nothing
. nub
)
. unzip
:: [[(Int, Int)]] -> Maybe [(Int, [Int])] - Scott Fleischman @scottfleischman
let
sing [] = Left "Too few" - matt @themattchan map ((head *** id ) . unzip)
- October 3rd, 2017:
you have [(1,[2,3,4]),(10,[5,6,7])]
you want [(1,2),(1,3),(1,4),(10,5),(10,6),(10,7)]
or, generally: [(a,[b])] -> [(a,b)]
Go! - bazzargh @bazzargh (uncurry (zip . repeat) =<<)
- Bruno @Brun0Cad (=<<) sequence
- Denis Stoyanov 🐜 @xgrommx fmap (uncurry (liftA2(,) . (:[])))
- Darren G @Kludgy I like that this doesn't unnecessarily implicate the sequentiality of bind.
- Darren G @Kludgy Funny this same product came up at work last week.
concatMap $ \(a,bs) -> fmap (\b -> (a,b)) bs
sing [x] = Right x
sing (_ : _) = Left "Too many"
valid = sing . nub
go = _1 valid . unzip
in traverse go
Tuesday, October 31, 2017
October 2017 1HaskellADay problems and solutions
- October 31st, 2017: Tuesday's #haskell problem has you save off the special characters from yesterday's exercise to a properties file. Today's #haskell solution: properties file created. We also output the special characters in context, which is nice.
- October 30th, 2017: Monday's #haskell problem we contextually find special characters in documents. Whoa! Today's #haskell solution finds that there are a lot of special characters in these documents!
- October 27th, 2017: 2017-10-27, a date where the month/day is an anagram of the year. How many days from today are anagrams of 2017? What are they? Today's #haskell solution: and we have a winner! A bunch of winners, actually for date anagrams in 2017.
- October 26th, 2017: Today's #haskell problem does what Google calls artificial-artificial intelligence analyses on NYT article archives. Today's #haskell solution: from one spreadsheet comes many! Nietzsche would be so proud of me rn.
- October 25th, 2017: Today's #haskell problem, instead of counting articles by topic, we divide articles into browsable/graphable topics. Today's #haskell solution we graph a slice of our NYT article archive.
- October 24th, 2017: Tuesday's #haskell exercise we read back in the articles stored as JSON then partition them by subcategory. Okay! Partitioned articles for today's #haskell solution.
- October 23th, 2017: Monday's #haskell problem we start to analyze our NYT article archive, selecting a topic to dissect. In the #haskell solution we read articles from our data store, then we save them out to file as JSON.
- October 20th, 2017: Today's #haskell problem: NYT article archive through a different lens, as nodes and relations in a graph database. Today's #haskell solution: we wanted #graph we got graph.
- October 19th, 2017: Customer: "Ooh! We love the charts you're making for us, but..." TIL that customers have big 'but's. Today's #haskell solution: And now we can read .gitignore-style configuration files.
- October 18th, 2017: Today's #haskell problem we archive the topics (and article topicality) of the NYT article set. We group data; we regroup data. Ah! The life of a Data Scientist! Today's #haskell solution via @d3js_org #dataviz
- October 17th, 2017: Today's #haskell problem: we build an app that queries the database and generates circle reports. A bit of database work then a bit of JSON to get us our charting tool for today's #haskell solution.
- October 16th, 2017: Thanks to @ahnqir we're looking at cities and skyscrapersfor today's #haskell problem. Ooh! Bar chart! Today's #haskell solution exclaims (proclaims? declaims?) "Look at Hong Kong with its highrises!"
- October 13th, 2017: Yesterday we built a little app (scanner), today we build something a little bigger: a #haskell #ETL application! Today we pull together NYT article parsing and database functions to create a #haskell ETL app! YAY!
- October 12th, 2017: Thursday's #haskell exercise is to build an app named scanner. I, for one, welcome our scanner overlords. Today's #haskell solution is the little scanner app that could!
- October 11th, 2017: Wednesday's #haskell problem: TIL that not all data in production is pristine. SHOCKER! So, okay, we know which document we are in when the less-than-pristine data fandangos on our perfect parser. Good.
- October 10th, 2017:
Boss: "That's a good chart, but can I have it in a spreadsheet?"
me: "But ..."
Boss: "Now."
Today's #haskell solution:
me: Ya wanna spreadsheet, boss? HERE'S YER SPREADSHEET! YA HAPPY?
Boss: um, ... 'yes'? - October 9th, 2017: Today's #haskell problem asks: can we chart just a few of the topics of the week archive of the NYT? Sure we can! Today's #haskell solution provides the top 5 topics then all topics with 10 or more articles.
- October 5th, 2017: Friday's #haskell exercise works with data-as-JSON and charting the analyses on the data. Today's #haskell solution has a LOT of circles in its visualization of NYT article topics. A LOT.
- October 4th, 2017: Today's #haskell exercise uses the NYT archive we've stored to look at trending topics and to visualize them. Today's #haskell solution we grab and group data we have in a data store.
- October 3rd, 2017: Building a set of words you key off of in your search for articles? MemoizingTable is today's #haskell problem. We parse a sliced of the NYT article archive and store articles and their respective subjects.
- October 2nd, 2017: Monday's #haskell problem looks at representing SQL join- or pivot-tables generally. Today's solution uses the Pivot values in #haskell to store data on a remote PostgreSQL database.
Tuesday, October 3, 2017
September 2017 1HaskellADay 1Liner problems and solutions
- September 26th, 2017:
art2RawNames art = Raw (artId art) <$> (Map.lookup "Person" $ metadata art)
curry away the 'art' var. ref: Y2017.M09.D26.Exercise - September 19th, 2017: The #1Liner to follow (next tweet) is a question based off a code snippet from Y2017.M09.D18.Solution. What is a better/more elegant definition?
fmap (wordStrength . wc) (BL.readFile filename) >>= \dict ->
Reformulate. Curry the dict-ref.
return (Map.insert filename dict m)
Subscribe to:
Posts (Atom)



















