- 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
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.
Thursday, November 30, 2017
November 2017 1HaskellADay problems and solutions
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
Subscribe to:
Posts (Atom)