- May 24th, 2016:
Given f :: a -> [a] -> b, g :: a -> c
Write h :: c -> [c] -> b, point-free, in terms of f and g
where h x y = f (g x) (map g y) - May 16th, 2016: The next 3 #1Liner are of a piece, using
data CmpV a =
Vec { len :: Int, top :: a, elts :: [a],
cmp :: CmpV a -> CmpV a -> Ordering } - Give the point-free definition of:
twoVs :: CmpV a -> CmpV b -> ([a], [b]) instance Ord (CmpV a) where
compare v1 = uncurry (cmp v1) . (v1,)
Make compare point-free by removing v1 from above definition- An Ord-instance needs an Eq-instance:
instance Eq a => Eq (CmpV a) where
v1 == v2 = elts v1 == elts v2
point-free-itize(==) - May 16th, 2016: You have the following lambda:
\x y -> x == y || fn x y
where fn :: a -> a -> Bool
Point-free-itize - obadz @obadzz without any fancy uses of the (a ->) Applicative :)
curry $ foldr (||) False . flip map [(==), fn] . flip uncurry - obadz @obadzz with fancy use of (a ->) Applicative :)
curry $ liftA2 (||) (uncurry (==)) (uncurry fn) - Noah Luck Easterly @walkstherain
curry $ uncurry (||) . (uncurry (==) &&& uncurry fn) - May 5th, 2016:
sames :: Eq a => [a] -> [a] -> Int
Counts equal values at the same indices in two lists.
What is the point-free definition?- joomy @cattheory
sames = curry (length . filter (uncurry (==)) . uncurry zip) - bazzargh @bazzargh and then Fatih Karakurt @karakfa
((length . filter id) .) . zipWith (==) - me: sum <<- fromenum="" li="" nbsp="" zipwith="">
- Noah Luck Easterly @walkstherain
sames = ((sum . map fromEnum) .) . zipWith (==) - `getSum . foldMap (Sum . fromEnum)` seems better than `foldr (bool id succ) 0` but both satisfy `[Bool] -> Int`
- Андреев Кирилл @nonaem00
let it = (length .) . (filter id .) . zipWith (==)
->
- joomy @cattheory
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.
Tuesday, June 14, 2016
May 2016 1Liners
One-liners
Wednesday, June 1, 2016
May 2016 1HaskellADay Problems and Solutions
May 2016
- May 31st, 2016: Today's #haskell problem gets a subsequence of DNA from ... DNA! http://lpaste.net/1527607897389793280 Today's #haskell solution: DNA subsequence GOT http://lpaste.net/5828328688629841920
- May 30th, 2016: We find the number of RNA strands that can generate a protein ... modulo reasonableness for today's #haskell problem http://lpaste.net/7114368903530151936 Today's #haskell solution shows us there are 'more than a few' RNA strands to compose some proteins http://lpaste.net/3827843057999413248
- May 27th, 2016: For today's #haskell problem we sing: No woman, Nah Trie! http://lpaste.net/8137189406290214912 Or: Breath-first Trie Traversal via the branches. We take breathing-lessons for today's #haskell solution http://lpaste.net/2088953736360624128
- May 26th, 2016: For today's #haskell problem we label the nodes of a Trie ... http://lpaste.net/658981668358455296 or at least we ... TRIE to! *groan Today's #haskell solution is a depth-first traversal of a Triehttp://lpaste.net/7964088321452277760
- May 25th, 2016: Today's #haskell problem ask you to exercise your probability muscles and look at some allele-pairingshttp://lpaste.net/7098281613896712192 That's all.
- May 24th, 2016: Reverse Palindromes in DNA strands?Yes. http://lpaste.net/4547532761941934080 Today's #haskell problem. Turns out there are lots of palindromes in DNA strands as today's #haskell solution shows. http://lpaste.net/8959978868165312512 Go figure.
- May 23rd, 2016: Splice, splice, baby! We get all Vanilla Ice with RNA with today's #haskell problem http://lpaste.net/2811938573572374528 We get our protein when with today's hand-rolled List-y-(\\) #haskell solution http://lpaste.net/5823105188059152384
- May 20th, 2016: For today's #haskell problem we consider the weighty matter of ... weighing matter http://lpaste.net/7500383126527410176 The weight's the thing Wherein I'll catch the conscience of the King ... no ... weight ...Today's #haskell solution http://lpaste.net/7743348996965400576
- May 19th, 2016: Today's #haskell problem looks at the Carmina Buranahttp://lpaste.net/684224423812661248 ... uh, no, it doesn't: Open Reading Frames. Today's #haskell solution sequences DNA strands to proteins http://lpaste.net/792645775074000896
- May 18th, 2016: If at first you do not succeed, trie and trie again today's #haskell problem http://lpaste.net/8558987235213443072 #trie #datatype
- May 17th, 2016: "Houston. We have a problem." #bigdata factors into today's #haskell problem of longest monotonic sequenceshttp://lpaste.net/6778179741435297792
- May 16th, 2016: Today's #Haskell problem asks for longest monotonic increasing/decreasing sequences ... in the small ... http://lpaste.net/7252474989977272320 So, the #haskell solution works against small data set, but since it's bifurcating, against large data sets? ... http://lpaste.net/7003206401061289984
- May 13th, 2016: #Rosalind is impatient. She doesn't have all day! Let's find a real-world solution to today's #haskell problem http://lpaste.net/8254705170412208128 Finding the longest common gene subsequence of 100 strands each 1000 nucleotides long in #haskell http://lpaste.net/2468395370904813568 Can you find faster?
- May 12th, 2016: We propose a little problem from Set Theory for today's #haskell problem http://lpaste.net/4050317579338645504 And we have today's #haskell in-a-perfect-world solution of the set-intersection of all subsequenceshttp://lpaste.net/1682855623517011968
- May 11th, 2016: Today's #haskell problem is all about the inods ... not 'inodes,' but 'internal nodes of an unrooted binary tree.' http://lpaste.net/7455193258755358720 "inods?" you say? "Of an unrooted binary tree?" you say? That would be pred . pred for today's #haskell solution http://lpaste.net/4766815087493120000
- May 10th, 2016: For today's #haskell problem we take it to the next level, see? and get variable-length strings as enumerated tokens http://lpaste.net/3180555571975684096 We pulled the powerSet Set.fromList Set.toList switcheroo for today's #haskell solution. http://lpaste.net/7501776843414962176
- May 9th, 2016: For today's #haskell problem we sing our A, B, Cs ... #Rosalind-style! http://lpaste.net/1445499963915108352 Today's #Haskell solution enumerates lexed tokens http://lpaste.net/503582828101894144
- May 6th, 2016: For today's #haskell problem we ask #Rosalind and she says 'Permutations.' So that's what we do! http://lpaste.net/6558920694606856192 This is the dawning of the age of Aquarius! "Hair" a movie about perms for today's #haskell solution http://lpaste.net/934285743432400896 @NickiElson3D
- May 5th, 2016: Today's #haskell problem: p-distance Matriceshttp://lpaste.net/818771459840147456 Believe you me: you will get a LOT of continued employment with these Today's #haskell solution is filed under #jobsecurity http://lpaste.net/5076187573303377920 #distanceMatrix
- May 4th, 2016: Today's #haskell problem we look at completing a graph into the Tree of Life http://lpaste.net/1315899789614776320 #Rosalind Today's #haskell solution is graph-y, or also take the approach of @bazzargh http://lpaste.net/1052721051462533120
- May 3rd, 2016: Today's #haskell problem looks at overlapping graphs, specifically for DNA strands from rosalind.info http://lpaste.net/8920617631791185920 Did you know a list is a graph? Today's #haskell solution was an elaboration of `isSuffixOf` http://lpaste.net/5785600391169179648 #Rosalind
- May 2nd, 2016: For today's #haskell problem we look at transforming our data into d3: "Data-driven document"-JSONhttp://lpaste.net/224067301371019264 For the #haskell solution we get a bird's-eye view of the Top5s stocks http://lpaste.net/7060337987313205248
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
define:
mkBB :: [a] -> Pt2D -> BBx
mkBB xs extents = Bx (0, length xs) (0,0) extents
points-free - 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
- April 29th, 2016: In today's #haskell problem we look at a set of Top5s markets data and define/quantify what looks 'interesting.' http://lpaste.net/8121634490738016256
- April 28th, 2016: Today's #haskell problem looks at 'solving' when a solution is not known a priori, and parallizing with antz http://lpaste.net/8170491646400528384
- April 27th, 2016: Today's #haskell problem has the antz foraging further afield (that is, in a much bigger matrix) http://lpaste.net/5667147688521498624 See what they find! Well, would you look at that! Today's #haskell solution sends more ants and gets a less costly result! Whoda thunk? http://lpaste.net/216918736328720384
- April 26th, 2016: SUPER SIZE ME! ... no, actually, just size me appropriately for today's #haskell problem http://lpaste.net/2187209441198211072
Solution has cluster nodes sized by cell-counts in each cluster: http://lpaste.net/5818908382240702464 - April 25th, 2016: The ants are Swarming! Today's #haskell problem the antz come marching one-by-one, hurrah! http://lpaste.net/4502369819319861248
Today's #haskell solution only took 153 antz to find the solution. YAY! Go, antz! Go! http://lpaste.net/7244247769668386816
- April 22nd, 2016: Today's #haskell problem is @projecteuler problem 81, also known as (for me:) the Kobayashi Maru http://lpaste.net/4178250065082580992 You give it a go. Totally NOT the solution to today's #haskell problem http://lpaste.net/8058369802856562688 ... unless you have more computational power than the Universe.
- April 21st, 2016: Today's #haskell problem asks: what's a pandigital prime? And which one is largest? http://lpaste.net/504585569821523968 via @projecteuler problem 41 And the largest Pandigital prime is (Just a). Yup, you heard it here first for today's #haskell solution http://lpaste.net/5597599669644427264
- April 20th, 2016: Today's #Haskell problem brings us back to Douglas Adams or projecteuler.net or both! with problem 42 http://lpaste.net/8181950129519984640 Words, words, and triangular words for today's #haskell solution http://lpaste.net/859266571875385344
- April 19th, 2016: In a shocking announcement, @geophf admits he's not a Haskell programmer for today's #haskell problem http://lpaste.net/7447463975479934976 oh, and R-Trie. From "PAPA" to "MAMMA" in Relational Trie and the 3-4-5 Trie tiers http://lpaste.net/259046704735584256 for today's #haskell solution.
- April 18th, 2016: For today's #haskell problem we look at the (reverse) Trie for efficient search of work suffixes http://lpaste.net/4221347562226974720 Assessment of the reverse trie for word suffix search: eh. http://lpaste.net/1782747088124116992
- April 15th, 2016: Today's #Haskell problem relates original data to scores on the data http://lpaste.net/5271793028346937344 We relate clustered cells to source data to allow further exploration in #haskell solution http://lpaste.net/6768261699876159488
- April 14th, 2016: We recolorize scorecards or we reintroduce meta-data into colored cells, either way, for today's #haskell problem http://lpaste.net/4184247669083865088 Today's #haskell solution gives us cells in the clusters enhanced with metadata http://lpaste.net/8455891905392148480
We expand the scope of the solution with big-indices and 3000 data points:
- April 13th, 2016: Today's #haskell problem tells us not to shun words ending with 'tion.' eheh. http://lpaste.net/8081525869924843520 We 'Trie' hard to get common prefixes for today's #haskell solution http://lpaste.net/5059758395683241984 Eheh: using Trie data structure to find prefixes
- April 12th, 2016: In today's #haskell problem we relate clustered data http://lpaste.net/9073884707980050432 We have a #dataviz of clustered data for today's #haskell solution http://lpaste.net/8982640331094753280 using a #graph #database
All the stocks in their clustersA query showing in which clusters AAPL, NFLX, and TWTR are
- April 11th, 2016: For today's #haskell problem we label then compact cells of heterogeneous data http://lpaste.net/6557878267389411328
Today's #Haskell solution gives us labeled, compacted data represented as SVG. http://lpaste.net/2873200763016839168 - April 8th, 2016: Today's #haskell problem LOOKS imposing, but it's really an Enum a reindexing problem; give it a go! http://lpaste.net/1555193256856256512 Today's #Haskell solution is 'fromEnum' http://lpaste.net/4814157348060790784 ... and this:
- April 7th, 2016: Today's #haskell problem returns to clusters, specifically 'clumping' (clustering) clusters http://lpaste.net/9172662547696844800 Today's #Haskell solution clumps clusters along mean-counts http://lpaste.net/4448502786170028032
- April 6th, 2016: You lookin' at Robert De Niro? Today's #Haskell problem: shoot him with Control.Arrow-syntax http://lpaste.net/6879084006575439872 Today's #Haskell solution ... with arrow syntax! http://lpaste.net/2056518229240578048
- April 5th, 2016: Today's #haskell problem is to create a symbol table compiler; wait, there's more: a symbol table compiler APP! http://lpaste.net/295071069348298752 So, today's #haskell solution wonders what happens if you're LOOKIN' at Rob't De Niro? ARE YOU LOOKIN' at HIM? http://lpaste.net/7366969987635871744
- April 4th, 2016: So, end of March we clustered some Market security data. Today's #haskell problem will query those clusters http://lpaste.net/5339634137026265088 So, in today's #haskell solution we learn $NFLX is in cluster 6 with 85 cells. http://lpaste.net/6805847212086525952 Hm. New clustering algorithm?
- April 1st, 2016: What if yesterday followed today? Today's #haskell problem: sorting unnormally-arrayed data, ... normalment oui. http://lpaste.net/3321894944162971648 We've 'resorted' to a better schema ... *groan* ... with today's #haskell solution http://lpaste.net/1909644297771155456
Thursday, April 7, 2016
March 2016 1HaskellADay 1Liners
One-liners
- 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 🎶 http://lpaste.net/7837739029373124608 ... but it likes it that way #introverproblems And the #haskell relinker-app is now integrated into the Top5s security scraper! http://lpaste.net/4419083329639284736 TA-DAH!
- March 30th, 2016: Today's #haskell problem we look at what ... well: 'today' means in a #graph DaaS http://lpaste.net/2053260260323360768 The #haskell solution gets you 'today' as a complete packagehttp://lpaste.net/5049502168399216640
- March 29th, 2016: For today's #haskell problem we look to reify prior-trading-day knowledge as relations http://lpaste.net/677389378498068480 Enhanced inter-day #trading analytics in #haskell on a #graph DaaS http://lpaste.net/1926020591458975744 (... 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 http://lpaste.net/5690415111206862848 The #solution gives us K-means clustering of score cards! YAY! http://lpaste.net/3576182129349885952
- March 24th, 2016: For today's #haskell problem we load our gap analyses into ScoreCards http://lpaste.net/6485373940918124544 eventually for clustering using K-means. And today's #haskell solution we get ScoreCards from CSV file and from the #graph DaaS endpoint http://lpaste.net/1163865820011429888
- March 23rd, 2016: Sing with me: ♫ Fall into the Gap 🎶 ... report http://lpaste.net/3030808839961182208 for today's #haskell problem It took a 'little bit' of work but today's #haskell solution gives us a 'little bit' of meta-datahttp://lpaste.net/7280141726189092864
- March 22nd, 2016: For today's #haskell problem we convert the JSON graph result into haskell structures http://lpaste.net/4829558181661245440 LOLNEAT! Today's #haskell solution gives us a working dataset from a #graph DaaS endpoint http://lpaste.net/7874827506493161472 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! http://lpaste.net/7339795115373756416 Okay, String returned from AWS DaaS #graph as today's #haskell solution http://lpaste.net/6813513488191717376 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! http://lpaste.net/8413387732209893376 Three #1Liner and an output file 1/3 the size later we have today's #haskell solution to the recompiler http://lpaste.net/4638823060617560064
- March 15th, 2016: For today's #Haskell problem we're warned to Beware the Ides of SymbolTables http://lpaste.net/6108657252669849600 ... but do we listen? Nooo! *stab-stab! So today's #haskell solution gives us a new static symbol-tablehttp://lpaste.net/4932809508989698048 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 http://lpaste.net/7793465205110865920 Okay, today's #haskell solution... did that, but we're missing some stock symbols http://lpaste.net/4928100283508064256 ... 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 http://lpaste.net/4278240752024158208 And today's #haskell solution gives us indices for the Array-god http://lpaste.net/7322735479504240640
- March 9th, 2016: Today's #Haskell problem we're going to take it easy: just write a compiler, is all http://lpaste.net/5530458314216833024 😎 Today's #haskell solution: Compiler: get http://lpaste.net/7970896540401139712 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 http://lpaste.net/4656681160972173312 Today's #haskell solution was a stop-gap measure for $NFLX http://lpaste.net/233537231812296704 ... eheh.
- March 7th, 2016: Today's #Haskell problem we look for scatterings of Afr- I MEANT $NFLX! in a sparse data set http://lpaste.net/5892060591643688960 Today's #haskell solution shows stocks with like-appearances to $NFLX on the Markets top 5s http://lpaste.net/5252814791931592704
- March 4th, 2016: 'Wuz gunna' do SPARQL query dump analysis but what is the SPARQL query? URL-UN-encoding http://lpaste.net/268889253654560768 for today's #haskell problem Today's #haskell solution shows 'punkin' is 'bettah' than RDF. http://lpaste.net/5388171163006402560 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 HXThttp://lpaste.net/6918752874277109760 "Parsing XML is Easy!" says @geophf for today's #haskell solution http://lpaste.net/4360598558106189824 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 http://lpaste.net/2940797818769506304 ('UN-JSON-ifying' is a word now) How many FromJSON instances was that? Dat iz one hella hint! in today's #haskell solution http://lpaste.net/7363580708683513856
- March 1st, 2016: Okay, it's not all tea and crumpets coding in #haskell. But I wish it were. Today's #haskell problem: http://lpaste.net/6471988009620209664 avoiding RDF. Today's #haskell solution showed me a fundamental truth: 1 HTTPS call is faster than 50 of them. http://lpaste.net/7390063266577252352
Thursday, March 17, 2016
February 2016: Haskell 1Liners
One-liners
- 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
Subscribe to:
Posts (Atom)

























