Thursday, May 5, 2016

April 2016 1HaskellADay 1Liners

  • April 15th, 2016:
    (\(intensf, list) -> map (second intensf) list) (insensifierFn, assocList)
    Point-free-itize this lambda
    • obadz @obadzz uncurry $ map . second
  • April 15th, 2016:
    foldr (\card -> let c = color card in mappend c *** ((idx card, c):))
           (mempty, []) cards
    Point-free-itize and de-let lambda
    • Gautier DI FOLCO @gautier_difolco foldr (uncurry (***) . (uncurry fmap . fmap (((,) =<< mappend) . color) . ((,) =<< ((:) .) . (,) . idx))) (mempty, []) cards
    • me: foldr (uncurry (***) . (mappend . snd &&& (:)) . (idx &&& color)) (mempty, [])
  • April 15th, 2016: map (\(idx, color) -> C idx (cell bb idx) color) assoclist
    point-free-itize the lambda in the map function.
    • Eyal Lotem @EyalL uncurry (C <*> cell bb) ?
      Not in front of a type checker, can't check myself :)
  • April 13th, 2016:
    point-free-itize lambda term in:
    uncurry (foldr (\a -> min a *** max a)) . ((head &&& head) &&& id)
    • obadz @obadzz liftA2 (***) min max
  • April 12th, 2016:
    minmax :: Ord a => [a] -> (a, a)
    minmax [1..9] = (1,9)
    in linear time.
    minmax = minimum &&& maximum
    fails as it's 2x too slow.
  • April 12th, 2016:
    You have (a,b) (c,d)
    You need (a*c, b*d)

    Well, we don't have all day! (Actually, we do) Get to it!
    Pointless; I MEAN POINT-FREE pls
    • lotz@Haskell㌠ @lotz84_ ((uncurry . flip . curry $ id).) . ((uncurry.) . uncurry . (flip.) . flip . flip) ((((flip . (flip.)) $ ((,).) . (*)).) . (*))
    • Olivier Iffrig @oiffrig Point-free but star-full: uncurry (***) . ((*) *** (*))
    • bazzargh @bazzargh curry((uncurry (*)) *** (uncurry (*)))
    • bazzargh @bazzargh knew there had to be a bimap answer, eventually got: curry ((bimap <$> id <*> id) (uncurry (*)))
    • obadz @obadzz join biliftA2 (*)
    • Андреев Кирилл @nonaem00 (((product *** product) . unzip) .) . (flip (:)) . (:[]) ... I clearly need more coffee this morning.
  • April 10th, 2016:

    data BBx = Bx (Int, Int) Pt2D Pt2D

    mkBB :: [a] -> Pt2D -> BBx
    mkBB xs extents = Bx (0, length xs) (0,0) extents
    • Gautier DI FOLCO @gautier_difolco
      -- LANGUAGE TupleSections
      data BBx = Bx (Int, Int) Pt2D Pt2D
      mkBB :: [a] -> Pt2D -> BBx
      mkBB = flip Bx (0,0) . (0, ) . length
    • Thomas D @tthomasdd mkBB = flip Bx (0,0) . (,) 0 . length
  • April 7th, 2016:
    type MList a n = [(a, n)]
    partSz :: Ord n => n -> MList a n -> (MList a n, MList a n)
    partSz µ = partition ((µ >) . snd)
    Define points-free
    • partSz = partition . (. snd) . (>)  -- via @gautier_difolco

Monday, May 2, 2016

April 2016 1HaskellADay Problem and Solutions

April 2016

Thursday, April 7, 2016

March 2016 1HaskellADay 1Liners

  • March 29th, 2016: You have a list, Show a => [a], of known-length n, n > 100 Show the first three and the last three elements of that list
  • March 28th, 2016: You have f :: c -> d and g :: a -> b -> c
    define (<<-) such that f <<- g is f (g a b)
    Does it exist already (in the Prelude, maybe)?
  • March 26th, 2016: insert1 :: Ord k => k -> a -> Map k [a] -> Map k [a] define, points-free, efficiently. (hint: it's not insertWith)
  • March 26th, 2016: sqDist :: Fractional ä => [ä] -> [ä] -> ä sqDist v1 v2 = sum (zipWith (\a b -> (a - b) ^2) v1 v2) Point-free-itize sqDist (and λ)
  • March 17th, 2016: for f :: (a -> b) -> (a, a) -> (b, b) define f
    • obadz @obadzz f = join bimap
  • March 17th, 2016: removeAll :: Eq a => a -> [a] -> [a]; define
    e.g.: removeAll '"' "(\"S312\", \"S204\")" ~> "(S312, S204)"
    • obadz @obadzz removeAll = filter . (/=)
    • Gautier DI FOLCO @gautier_difolco ... same
  • March 17th, 2016:
    f, g :: (String, String) -> String
    let ab = ("a", "b")
    f ab ~> "(\"a\", b)"
    g ab ~> "(a, \"b\")"
    define h that generalizes f and g
    • Gautier DI FOLCO @gautier_difolco
      cp x y (a,b) = concat ["(", x a, ",", y b, ")"]
      f,g :: (String, String) -> String
      g = cp id show
      f = cp show id

Thursday, March 31, 2016

March 2016 1HaskellADay Problems and Solutions

  • March 31st, 2016: Today's #haskell problem is ♫ alone again, naturally 🎶 ... but it likes it that way #introverproblems 
    And the #haskell relinker-app is now integrated into the Top5s security scraper! TA-DAH! 

  • March 30th, 2016: Today's #haskell problem we look at what ... well: 'today' means in a #graph DaaS 
    The #haskell solution gets you 'today' as a complete package
  • March 29th, 2016: For today's #haskell problem we look to reify prior-trading-day knowledge as relations Enhanced inter-day #trading analytics in #haskell on a #graph DaaS (... in 6 lines of code.) 
  • March 25th, 2016: For today's #haskell problem we take the score cards we've created from the #graph DaaS endpoint and cluster them The #solution gives us K-means clustering of score cards! YAY!
  • March 24th, 2016: For today's #haskell problem we load our gap analyses into ScoreCards eventually for clustering using K-means. And today's #haskell solution we get ScoreCards from CSV file and from the #graph DaaS endpoint
  • March 23rd, 2016: Sing with me: ♫ Fall into the Gap 🎶 ... report for today's #haskell problem It took a 'little bit' of work but today's #haskell solution gives us a 'little bit' of meta-data
  • March 22nd, 2016: For today's #haskell problem we convert the JSON graph result into haskell structures LOLNEAT! Today's #haskell solution gives us a working dataset from a #graph DaaS endpoint Now, let's git bizzy!
  • March 21st, 2016: For this week's set of #haskell problems we're going to go against a #graph #database running on AWS! YIPPEE! Okay, String returned from AWS DaaS #graph as today's #haskell solution Tomorrow we'll look at parsing the JSON.
  • March 16th, 2016: So, you've heard of this thing called a 'compiler,' right? For today's #haskell problem we're building a REcompiler! Three #1Liner and an output file 1/3 the size later we have today's #haskell solution to the recompiler
  • March 15th, 2016: For today's #Haskell problem we're warned to Beware the Ides of SymbolTables ... but do we listen? Nooo! *stab-stab! So today's #haskell solution gives us a new static symbol-table That's great. The Show and Read definitions, though?
  • March 14th, 2016: Today, we transform the superabundantly quoted mess@neo4j gives us as a CSV export into ... well: CSV Okay, today's #haskell solution... did that, but we're missing some stock symbols ... we'll look at that 'tomorrow.'
  • March 11th, 2016: I hate the stodgy internet at work. Today's #haskell problem is to improve ScoreCard data type to use Ix-constrained values And today's #haskell solution gives us indices for the Array-god
  • March 9th, 2016: Today's #Haskell problem we're going to take it easy: just write a compiler, is all 😎 Today's #haskell solution: Compiler: get I didn't ask for this in the problem statement, but I also gave a Read-instance for types extracted via SymbolTable.
  • March 8th, 2016: For today's #haskell problem we are looking for securities with similar max-gaps in Markets top5s appearances Today's #haskell solution was a stop-gap measure for $NFLX ... eheh. 
  • March 7th, 2016: Today's #Haskell problem we look for scatterings of Afr- I MEANT $NFLX! in a sparse data set 
    Today's #haskell solution shows stocks with like-appearances to $NFLX on the Markets top 5s 
  • March 4th, 2016: 'Wuz gunna' do SPARQL query dump analysis but what is the SPARQL query? URL-UN-encoding for today's #haskell problem Today's #haskell solution shows 'punkin' is 'bettah' than RDF. Funny, that: the universal quantifier works, too.
  • March 3rd, 2016: Now, for something completely different for today's #haskell problem, parsing XML document of the US States with HXT "Parsing XML is Easy!" says @geophf for today's #haskell solution Yeah, but is parsing CSV easier? @geophf Yeah, but ...
  • March 2nd, 2016: UN-JSON-ifying that JSON, baybee! is on the menu for today's #haskell problem ('UN-JSON-ifying' is a word now) How many FromJSON instances was that? Dat iz one hella hint! in today's #haskell solution
  • March 1st, 2016: Okay, it's not all tea and crumpets coding in #haskell. But I wish it were. Today's #haskell problem: avoiding RDF. Today's #haskell solution showed me a fundamental truth: 1 HTTPS call is faster than 50 of them.

Thursday, March 17, 2016

February 2016: Haskell 1Liners

  • February 11th, 2015: rewrite
    \n -> mapM f (replicate 10 n)
    using replicateM instead
    where f :: Monad m => Int -> m a
    • Gautier DI FOLCO @gautier_difolco replicateM 10 . f

Monday, February 29, 2016

February 2016 1HaskellADay Problems and Solutions

February 2016

  • February 29th, 2016: For today's #LeapDay #haskell problem, @geophf asks for your (π) deets! courtesy of @OnThisDayinMath Today's #haskell solution *Main> last10idx (take 1000000 π) ~> 999699 @OnThisDayinMath 
  • February 26th, 2016: Doing some geo-plotting with #Wikidata for today's (coming up) #haskell problem ... and we extracted State capitol lat/longs from #wikidata with this #haskell solution 
  • February 25th, 2016: A little bit of parsing wikidata from a US State/Capitol SPARQL query for today's #haskell problem Got SPARQL-y, and today's #haskell solution gets you State capitol data ... in #haskell! (Did I mention #haskell?)
  • February 24th, 2016: Yesterday we sliced, sliced, baby! For today's #haskell problem, we get all dicy wid it! converting triples to acids You get a protein, and YOU get a protein, and EVERYBODY GETS A PROTEIN in today's #haskell solution
  • February 23rd, 2016: Today's #Haskell problem has us singing "Splice, Splice, baby!"  
    And the #haskell solution uses Comonads to chunk the input gene sequence to nucleotide triples
  • February 22nd, 2016: This week we'll look at gene sequencing. Today's #haskell problem we'll create a bi-directionally mapped CODON table And the #haskell solution tabled that CODONs! improving the original along the way.
  • February 19th, 2016: For today's #haskell problem, we deliver our customer the product: codes and, well: codes for their reports. YAY! Annnnnnnnnddddd the file of TWENTY-ONE THOUSAND NINE HUNDRED CODES! 
  • February 17th, 2016: Today's #haskell problem gives ONE MILLION codes to the reports-god ... *ahem* I MEANT reports-GENERATOR! ... And the solution:
    Mr. NumberTwo: Sorry, sir, it's only 21900 codes.
    Dr. Evil: ... 
  • February 16th, 2016: Today's #haskell problem has us parsing MORE! This time regional offices and business units And we have our Regional offices and business units as a #graph and as a #haskell module 
  • February 15th, 2016: This week we'll be looking at accounting and generating reports! Because YAY! Today's #haskell problem: parsing food Foods: Parsed (but hopefully not eaten. YUCK!), Snark: captured, Chart: pie-d ... HUH?!? 
  • February 12th, 2016: Today's #Haskell problem generalizes random strings to sequences of enumerated values, specifically Gene sequences Today's #haskell solution surely gives us a lot of nucleotides to consider!
  • February 11th, 2016: Writing random strings for today's #haskell problem because that's every coder's dream-project. Today's #haskell solution does some stats on the generated random strings
  • February 10th, 2016: You generate a set of 'random' numbers. The next set is very similar ... let's fix that for today's #haskell problem Today's #haskell solution made rnd more rnd, because reasons
  • February 9th, 2016: We learn the past tense of the verb 'to see' is 'See(d),' 'saw(ed),' or 'sowed' and we generate some random numbers. ICYMI that was the announcement for today's #haskell problem: it's a Big Generator. Yes. It is. (*groan Okay, I'll stop) (NEVER!)
    The #haskell solution has us
    shiftR to the Right ...
    movin' to the Left ...
    we are the voices of the
    Big Generator!
  • February 8th, 2016: Creating a random seed from POSIX time for today's #haskell problem En-split-ified POSIX time
  • February 5th, 2016: We tackle an Amino Acid CODON table for today's #haskell problem suggested by a GATTACA-tweet by @randal_olson The Amino Acid table as a #graph #haskell-solution

  • February 4th, 2016: Today's #haskell problem has us create the cal (not Ripken) app Today's #haskell solution has us Rikpenin' dat Cal!
  • February 3rd, 2016: The Days of Our Lives (or at least of the year) for today's #haskell problem These were the best days of our lives! / Back in the Summer of '69!
  • February 2nd, 2016: Dates and Days for today's #haskell problem Date nuts and Grape nuts! ... no ... wait.
  • February 1st, 2016: Happy February, everyone! Today's #haskell problem: arrows, monads, comonads!

Thursday, February 11, 2016

January 2016 Haskell One-liners

  • January 26th, 2016: define line2Bio so that
    *Main> line2Bio "Birches by Robert Frost" ~> ("Birches","Robert Frost")
    (in 1 line)
    • Gautier DI FOLCO @gautier_difolco
      import Data.Bifunctor
      line2Bio = bimap unwords (unwords . tail) . break (== "by") . words
    • matthieu bulté @matthieubulte
      line2Bio = on bimap (unwords .) id tail . break (== "by") . words
  • January 26th, 2016: define swap points-free:
    swap :: (a,b) -> (b, a)
    • matthieu bulté @matthieubulte
      swap = uncurry (flip (,))
    • Noah Luck Easterly @walkstherain
      uncurry $ flip (,)
    • Андреев Кирилл @nonaem00
      import Control.Arrow
      swap = snd &&& fst