- July 14th, 2016: So you have x :: [a] in the IO monad, and the function f :: a -> b What is the expression that gets you IO [b]?

# Typed Logic

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.

## Saturday, August 20, 2016

### 1Liners for July 2016

## Sunday, July 31, 2016

### July 2016 1HaskellADay Problems and Solutions

###
**July 2016**

- July 28th, 2016: Lao Tzu says what is crooked cannot be made straight... but what does that guy know? Today's #haskell exercise
- July 27th, 2016: For today's #haskell exercise we look at the shortest distance between any two points in a graph. Today's #haskell solution uses brute-force to find shortest distance paths, which works for small graphs
- July 26th, 2016: Today's #haskell exercise looks at (one aspect of) shortest pathing through graphs. Today's #haskell solution is the shortest path through a graph, NOT using continuations. *WHEW*
- July 25th, 2016: For today's #haskell problem we look at pathing through graphs with cycles. We avoid 'teh Sadeness' with today's #haskell solution of pathing graphs with cycles
- July 22nd, 2016: For today's #haskell exercise we tear apart #graph-construction or -pathing ... or both. Today's #haskell solution works PERFECTLY if your graph doesn't have cycles like this one!
- July 21st, 2016: Today's #haskell problem looks at simplifying the representation of pathing through #graph data The #haskell solution paths through a graph, but ... hm: not perfectly. We'll look at complete pathing today.
- July 20th, 2016: Yesterday, I didn't give complete information for the figure. Today's #haskell exercise rectifies that #graph Today's #haskell solution is a #graph of complete information of the figure, and a partial look into pathing
- July 19th, 2016: For today's #haskell exercise we count crows. I mean triangles ... I mean (properly) trigons
- July 15th, 2016: I posted this problem on github this morning but did not announce: #Haskell exercise: extract date from twitter JSON So, BANG! right on the heels of the exercise announcement: Data.Aeson and a little Day-parsing for the solution.
- July 14th, 2016: Today's #haskell exercise ... get this! ... helps you find Haskell exercises, both problems and solutions! #graph For today's #haskell solution I went the graph DaaS-route to extract @1HaskellADay problems and solutions
- July 12th, 2016: Today's #haskell excercise compiles the RID into a Haskell module and analyzes Pride and Prejudice
- July 11th, 2016: Today's #haskell exercise decodes the RID/Regressive Imagery Dictionary from JSON
- July 8th, 2016: Today's #haskell exercise brings together replacing one set of symbols with another and qualified names in XML The #haskell solution today WEARYs me, but it, surprisingly, has COFFEE, so I'm good! Encoding strings-as-symbols.
- July 7th, 2016: Today's #Haskell problem is to write Bram Stoker's Dracula as Jane Austen would have ... erhm, sort of. Not literature: a rehash of Bram Stoker's Dracula using Jane Austen's words .. but then: have you read the original?
- July 6th, 2016: So, loading up an encoding table is on the plate for today's #haskell exercise. We encode Pride and Prejudice as symbols then save it as a #haskell module
- July 5th, 2016: We look at encoding names and qualified names for today's #haskell exercise. For today's #haskell solution we encoded (qualified) names as symbols using SymbolTable
- July 4th, 2016: (summary) Report generation is the name of the game for today's #haskell exercise. And so in today's #haskell solution we generate a report! BOOP!
- July 1st, 2016: *WHEW* It took two days to marshall the data set for today's #haskell exercise: convert junit test result-XML to CSV And the #haskell solution involves TagSoup parsing at applicative functors

## Thursday, July 14, 2016

### 1HaskellADay 1Liners June 2016

- June 13th, 2016:

You want this list:`[1, -1, 1, -1, ...]`

How would you produce this value in #Haskell ?- Wai Lee Chin Feman @wchinfeman

https://gist.github.com/skatenerd/08d70c45499e1610206a

(set plop to be identity, and set transformstate to be (*) -1) - Philipp Maier @AkiiZedd `
`iterate negate 1`

’ - Patrick Mylund @pmylund
`concat $ repeat [1, (-1)]`

- Gary Fixler @gfixler No need for the parens in a list.

- Jeff Foster @fffej and Kevin Meredith @Gentmen
`iterate (* (- 1)) 1`

- Spencer Janssen @spencerjanssen and Андреев Кирилл @nonaem00
`cycle [1, -1]`

- Philipp Maier @AkiiZedd:

I’m curious: Since concat is O(n) wouldn’t it take more and more time depending on how many items you take? - Patrick Mylund @pmylund Looks like they compile to the same thing https://gist.github.com/patrickmn/9a92ab2a088018b2c0631f3bcfd60ebe
- Philipp Maier @AkiiZedd I’m actually surprised the compiler can optimise this away :o Thanks for showing me
`ddump-simpl`

! - Eyal Lotem @EyalL
`concat`

is`foldr (++)`

, not`foldl`

. O(1) work is done to produce the next item.`[1,-1]++([1,-1]++(...`

- Philipp Maier @AkiiZedd:

- Wai Lee Chin Feman @wchinfeman
- David Turner @DaveCTurner I'd actually write '
`cycle [1,-1]`

' but I like the elegant, alliterative obscurity of '`iterate negate 1`

' - Fatih Karakurt @karakfa
`alt=1:[-x|x<-alt]`

## Friday, July 1, 2016

### June 2016 1HaskellADay Problems and Solutions

- June 29th, 2016: Today's #Haskell exercise is REALLY HARD! ... for Big Gov't. Can you solve it? A little bit of (well-typed) Prolog-like code gets us our #haskell solution for today
- June 28th, 2016: For today's #haskell problem we do ... NOTHING! But we are introduced to coding software for a huge bureaucracy ... AAAAANNNDDD three System imports and we've got today's #haskell solution. Groovy!
- June 24th, 2016: #haskell problem today charts Stochastic Oscillators of a security and includes a 'malus' problem: report generation
- June 23rd, 2016: Today we look at using #haskell to chart moving averages of a stock's prices https://github.com/geophf/1HaskellADay/blob/master/exercises/HAD/Y2016/M06/D23/Exercise.hs https://twitter.com/logicalgraphs/status/743409829843243008
- June 21th, 2016: I pushed today's #haskell problem last night on git but did I announce it? sigh Complex roots of quadratic equations https://github.com/geophf/1HaskellADay/blob/master/exercises/HAD/Y2016/M06/D21/Exercise.hs The #haskell solution gives us the Complex roots to any (Real) quadratic equation https://github.com/geophf/1HaskellADay/blob/master/exercises/HAD/Y2016/M06/D21/Solution.hs
- June 20th, 2016: Solving quadratic equations is on the plate for today's #haskell exercise https://github.com/geophf/1HaskellADay/blob/master/exercises/HAD/Y2016/M06/D20/Exercise.hs
It's not every day I codeThank you, #haskell, for today's solution to do sohttps://github.com/geophf/1HaskellADay/blob/master/exercises/HAD/Y2016/M06/D20/Solution.hs
- June 17th, 2016: My, my! Where has the day flown? Today's #haskell problem is to reinvent charting API! ... or not. https://github.com/geophf/1HaskellADay/blob/master/exercises/HAD/Y2016/M06/D17/Exercise.hs
- June 16th, 2016: Today's #haskell exercise looks at representing $TWTR data as candlesticks https://github.com/geophf/1HaskellADay/blob/master/exercises/HAD/Y2016/M06/D16/Exercise.hs
- June 15th, 2016: For today's #haskell problem, we round out the Data.Matrix module with the definition of the identity matrix https://github.com/geophf/1HaskellADay/blob/master/exercises/HAD/Y2016/M06/D15/Exercise.hs There are many ways to define the identity matrix. Today's #haskell solution does so with Cellular Automata Rule 16 https://github.com/geophf/1HaskellADay/blob/master/exercises/HAD/Y2016/M06/D15/Solution.hs
- June 14th, 2016: Yesterday we computed the matrix determinant, today we'll invert a matrix and use it to solve systems of equations https://github.com/geophf/1HaskellADay/blob/master/exercises/HAD/Y2016/M06/D14/Exercise.hs Today's #haskell solution inverts a matrix BECAUSE WE FEEL LIKE IT! Yeah https://github.com/geophf/1HaskellADay/blob/master/exercises/HAD/Y2016/M06/D14/Solution.hs
- June 13th, 2016: For today's #haskell problem we *ahem* DETERMINE (eventually) to solve systems of equations https://github.com/geophf/1HaskellADay/blob/master/exercises/HAD/Y2016/M06/D13/Exercise.hs The determinant is the sum of the products of the first row with the sub-matrix determinants, right? RIGHT! https://github.com/geophf/1HaskellADay/blob/master/exercises/HAD/Y2016/M06/D13/Solution.hs
- June 10th, 2016: Today's #haskell problem looks at box-and-whiskers charting of data https://github.com/geophf/1HaskellADay/blob/master/exercises/HAD/Y2016/M06/D10/Exercise.hs Boxes for realz, yo: https://en.wikipedia.org/wiki/Box_plot The #haskell solution has @geophf writing 'uncurry uncurry' and sincerely meaning it! 😱 https://github.com/geophf/1HaskellADay/blob/master/exercises/HAD/Y2016/M06/D10/Solution.hs and box:
- June 9th, 2016: Triangles are on my mind for today's #haskell problem: https://github.com/geophf/1HaskellADay/blob/master/exercises/HAD/Y2016/M06/D09/Exercise.hs … bisecting them, then trisecting them.
- June 8th, 2016: For today's #haskell problem, just what you've always wanted: MATH HOMEWORK! We find the intersection of two lines https://github.com/geophf/1HaskellADay/blob/master/exercises/HAD/Y2016/M06/D08/Exercise.hs
**ANNOUNCEMENT:**lpaste.net is acting up; cloning original @1HaskellADay github repository and putting the exercise there. FYI- June 6th, 2016: Today's #haskell problem explores superstring theory http://lpaste.net/6891096377267322880 No, it doesn't, but saying that has a certain ring to it!
- June 3rd, 2016: We saw a solution to perfect matching yesterday. For today's #haskell problem, let's efficient-ize it! http://lpaste.net/1128504074363207680
- June 1st, 2016: Today's #haskell problem is pretty much counting complements ... pretty much. http://lpaste.net/9130195410017583104 These apparently simple problems are actually rather hard. Today we have a #P-complete #haskell solution http://lpaste.net/670419007353913344

## Tuesday, June 14, 2016

### May 2016 1Liners

**One-liners**

- 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

## 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

Subscribe to:
Posts (Atom)