Friday, October 30, 2015

October 2015 1HaskellADay Problems and Solutions

October 2015

  • October 29th, 2015: This is a perfect introduction to today's #haskell problem: dynamic predictions because cats. And today's #haskell problem has the added benefit of containing the longest epic mid-type-declaration-comment of epic epicness. Epically. ... but what you didn't see for today's #haskell problem is the preparation #fallingasleepoverthekeyboard #again And the 'S' in the anSwer is not for 'S'tatistician, but for geophf waiting for a 'S'uper heroine to give the anSwer
  • October 28th, 2015: Today's #haskell problem, we DEFINE WHAT 'AVERAGE' IS! Nope. But we do take on predictive analytics! So there's that. And here's the predictions-distributions. One day we'll even do ROC-analysis. Or not.
  • October 27th, 2015: For today's #haskell problem we say "HEY! YOU! GET YOU SOME RANDOM, YO!" and then define a random number generator A (random) solution (not really) to yesterday's random (really) #haskell problem
  • October 26th, 2015: Well, bleh! It only took all day to compose, but here's today's #haskell problem! "Learning Haskell!" Okay, that (randomly) hurt! -- one possible solution to this problem is posted at
  • October 23rd, 2015: Today's #haskell problem is thanks to Jim Webber's keynote at @GraphConnect is about triadic closure
  • October 22nd, 2015: Today's #haskell problem is thanks to Jim Webber's keynoteat the @neo4j @GraphConnect: WWI Alliances  WWI-Alliances … and as a @neo4j-graph 
  • October 16th, 2015: Today's #haskell problem asks you to create MAJYCK! with LENSES over MATRICES using SCIENCE! (lens = magic ICYMI)
  • October 15th, 2015: Today's #haskell problem is a real (silly) problem: 'efficientize' row and col definitions for Data.Matrix Zippidy Doo-Dah! Zippidy day! My, oh, my we've 'efficientized' Matrix RowCol (that scans. Kinda)
  • October 14th, 2015: For today's #haskell problem we look at multiplying matrices, because SCIENCE! Today criss-cross is gonna JUMP-JUMP! ... and sauce the apples (What this has to do with matrix-multiplication, I do not know)
  • October 13th, 2015: A rose by any other name would smell as sweet. A matrix-transpose by any other name is still today's #haskell problem Today we transpose matrices ... LIKE A GANGSTA!
  • October 12th, 2015: We go from eh-matrices to ÜBERMATRICES for today's #haskell problem And we übered those matrices at
  • October 8th, 2015: We haven't touched Data.Matrix in a while, and it didn't age well. Let's fix this for today's #haskell problem Matrices, REBORN! (or at least, prenatal, but we'll get there)
  • October 7th, 2015: So, after all that work making DList Foldable/Traversable/Monadible (eh?) TODAY's #haskell problem relaxes MultiMap That MultiMap is now hella-relaxed, yo!
  • October 6th, 2015: So YESTERDAY we looked at Foldable. @argumatronic said "Step it up: do Traversable!" So for TODAY'S #haskell problem So we WuTang Traversible CLANNEDthat solution!
  • October 5th, 2015: For today's #haskell problem we go from Monadical to Foldable, thanks to @argumatronic Wait. Is 'monadical' a word? DList. Foldable instance. Done.
  • October 2nd, 2015: For today's #haskell problem we make multimaps fast with difference lists ... OR. DO. WE! And today we find out HOW FAST MULTIMAPS ARE WITH DLISTS! (in all caps, no less)
  • October 1st, 2015: Yesterday we made Difference Lists Applicative, for today's #haskell problem we make them monadic So, difference lists are monadic now ... so there's that ...

Wednesday, October 21, 2015

GraphConnect Lightning Talk: Project Planning Troubles? Graph Theory to the Rescue!

Project in Trouble?
Doug Auclair
for NCI, inc.
Washington, D.C.

The 4-slide Presentation
  • Okay, what're we talkin' 'bout here?
  • So, borin', amirite?
  • The State of Graphs (at NCI)
  • I can haz Linkies, plz

The Project/The Plan
  • US Gov't project: Spreadsheet management
  • The 'need': Okay, they don't know what they need
  • The 'what they don't want': excitement
  • What they got: DIS!

  • Project successes/progress:
    • Gov't client: One delivery, on approved software list
    • Commercial client: Our first, PoC-stage
    • What we need, yo!


(What they had...)
(eww, spreadsheets, blah-bla-blah)

(but under the covers)
(oooh! graphs!)

(sigh, more spreadsheets)
(WITH the answers they needed, s'il vous plaît)

(sigh, spreadsheets)
(but showing data in ways they couldn't see before)

Unclustered, but colorized-by-algorithm data

... to this
Clustered data, represented colored-by-datum, and expandable-on-demand nodes

Wednesday, October 14, 2015

September 2015 1HaskellADay 1Liners

  • September 18th, 2015:
    Okay so we know the tuple2list function doesn't exist generally, but ...
    t2l :: (a,a) -> [a]
    define t2l points-free
    • JP @japesinator uncurry ((. pure) . (:))
    • 熊井さん @lotz84_ reverse . uncurry ((flip (:)) . (:[]))
    • bazzargh @bazzargh ap[fst,snd].(:[])
  • September 17th, 2015:
    (bifunctor crowd is rubbing their hands here...)
    you have x,y :: [(a, b)]
    you need p,q :: [b]
    define fi such that fi (x,y) ~> (p,q)
    • obadz @obadzz fi = bimap f f where f = map snd ?
      • [revised:] fi = join bimap f where f = map snd
  • September 17th, 2015:
    dist :: (Num a, Floating a) => [a] -> [a] -> a
    dist is the sqrt of the sum of the squared-diffs
    define the curried fn: dist vs
  • September 11th, 2015: You have this: doubleplus = join (***) (+) define f point-free: f :: Num a => (a, a) -> (a, a) -> (a, a) f (a,b) (c, d) = (a+c, b+d)
    • obadz @obadzz (<<*>>) . (<<*>>) ((+), (+))
    • Greg Manning @ghyu f = uncurry bimap . doubleplus
  • September 8th, 2015: Given f :: a -> b -> c define g :: [(a, [b])] -> [c] points-free
    • Freddy Román @frcepeda g = concatMap (uncurry (map . f))
    • Gautier DI FOLCO @gautier_difolco
      concatMap (uncurry (zipWith ($)) . bimap (map f . repeat) id)
    • Daniel Gazard @danielgazard g = map (uncurry f) . concatMap (uncurry ((<$>) . (,)))
  • September 8th, 2015: Given f :: Monoid b => [a] -> b
    define b :: [a] -> (b, [b]) -> (b, [b]) points-free
    such that
    b c (x, r) = (x `mappend` f c, f c:r)
    • Chris Copeland @nopasetic b = uncurry bimap . bimap ((<>) . f) ((:) . f) . join (,)
    • Gautier DI FOLCO @gautier_difolco uncurry bimap . bimap (<>) (:) . join (,) . f
  • September 8th, 2015: Given data X a b c = X a b c
    and f :: a -> b
    define foo :: a -> c -> X a b c
    • failingattempt @failingattempt foo = X <*> f
  • September 4th, 2015: summer :: (a, Float) -> (a, Float) -> (a, Float)
    summer (x, a) (_, b) = (x, a + b)
    define summer, points-free
    • Stijn van Drongelen @rhymoid fmap . (+) . snd
  • September 3rd, 2015: suggested by @BeRewt: f :: [a -> b] -> a -> [b] define f points-free
    • \[ c^3 \] @das_kube sequence
    • Matthew Avant @mavant flip $ (<**>) . pure
  • September 3rd, 2015: What is it with y'all's #1Liner-speed-of-response? (I'm lovin' it, actually) sq :: Num a => a -> a sq x = x * x define sq points-free
    • Nicoλas @BeRewt join (*)
    • \[ c^3 \] @das_kube uncurry (*) . (id &&& id) (yes, ugly)
  • September 3rd, 2015: snds :: (a,b) -> (a,b) -> (b,b) define snds, points-free
    • September 3rd, 2015: tuple :: a -> b -> (a, b) define tuple, points-free
      • Nicoλas @BeRewt (,)
      • \[ c^3 \] @das_kube curry $ id *** id
      • Olivier Iffrig @oiffrig tuple = (,) Alternatively, tuple = curry id
    • September 3rd, 2015:
      you have f :: a -> b -> c you want g :: (a -> b -> [c]) -> a -> b -> d convert f to function that is accepted by g
      • obadz @obadzz ((:[]) .) . f
        • Nicoλas @BeRewt I prefer 'return' to '(:[])'
      • Matthew Avant @mavant ((.).(.)) (:[]) f, I suppose
    • September 1st, 2015: You have Functor-instance R a, declared R (a,a,a) You have f :: a -> a -> a define mappend :: R a -> R a -> R a, using f once only
      • obadz @obadzz unless you've got an applicative instance then mappend = liftA2 f

    Thursday, October 1, 2015

    September 2015 1HaskellADay Problems and Solutions

    • September 30th, 2015: Now, not only DLists are Functors, for today's #haskell problem we make them Applicative! Come to find that Applied Applicative DLists taste like Apples
    • September 29th, 2015: For today's #haskell problem we look at DLists as Functors! I know! Exciting! and we enfunctorfy DLists ... which are already functions ... ... hmmm ... That sounds like DLists are APPLICATIVE!
    • September 28th, 2015: So we indexed a set of rows last week, let's re(re)cluster them, AGAIN! for today's #haskell problem. And now we re(re)clustered the data, now with colors!
    • September 24th, 2015: Okay, yesterday we indexed rows, so, for today's #haskell problem, let's save and load those rows as CSV The solution to this problem has no title (oh, well!)
    • September 23rd, 2015: Data Row, o, Data Row: wherefore art thoust identity? Today's #haskell problem adds unique ids for rows of data Simply by using Data.Array we get our data in (uniquely-identified) rows
    • September 22nd, 2015: For today's #haskell problem we go To Infinity ... and Beyond. Yes: we're coding Haskell-on-the-web, yo! simpleHTTP makes HTTP GET-requests, ... well: simple!
    • September 21st, 2015: For today's #haskell problem, we'll fade a circle to black
    • September 17th, 2015: For today's #haskell problem, we receive data one way, but want to see it in another way. What to do? Data. EnCSVified. (that's a word, now)
    • September 16th, 2015: Today's #haskell problem asks 'why JSONify when you can represent clusters yourself?' Why, indeed!
    • September 15th, 2015: For today's #haskell problem we 'unJSONify' some, well, JSON
    • September 14th, 2015: For today's #haskell problem, we relook and recenterclusters from the cluster center So, re-en-cluster-i-fied ... uh: clusters! YAY! (with, ooh! pics!) 
    • September 11th, 2015: Yesterday we displayed one cluster. For today's #haskell problem, let's display them all!
    • September 10th, 2015: This past week we've been clustering data, for today's #Haskell problem we look at visualizing one of these clusters Cluster: shone! ('Schön'? sure!) 
    • September 9th, 2015: Okay, yesterday we clustered some data. For today's #haskell problem: let's see some clustered results, then! It don't mean a thing, ... If it ain't got the (spreadsheet/CSV) schwing.
    • September 8th, 2015: Today we get to do what all those other peeps do in other programming languages. Today we get to WRITE A PROGRAM! wow. I'M K-MEANSIN' ON FIRE TODAY!(okay, geophf, calm down now) A program in Haskell
    • September 7th, 2015: Happy Labor Day in the U.S.A. Today's #haskell problem is to look at recentering clusters for the K-Means algorithm SEMIGROUPOID! (not 'monoid') is the key the solution for today's #haskell problem (ScoreCard has no valid 'zero')
    • September 4th, 2015: Today's #haskell problem we store color-coding for score cards we obtain from rows of data And, color-coded score cards ... SAVED! (makes me wanna scream 'SAIL!')
    • September 3rd, 2015: For today's #haskell problem we look at reclustering the rows of data using K-Means clustering K-Means clustering in #haskell (well, for 1 epoch. Something's not right with step 3: recentered) (and it's DOG-slow)
    • September 2nd, 2015: Drawing information from #BigData is magical, or so says today's #haskell problem Ooh! Big Data is o-so-pretty! But what does it mean? Stay tuned! 
    • September 1st, 2015: For today's #haskell problem we look (obliquely) at the problem of 'indices as identity' What is identity, anyway? 100+ clusters for 3,000 rows? Sounds legit.