# News aggregator

### Extending Compiler With Authorized Types

### Douglas M. Auclair (geophf): 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

### Building shared library to be called from C

### Simple Interpreter with State Monad

### 18th International Symposium on Principles and Practiceof Declarative Programming PPDP 2016 - 2nd call for papers

### wren gayle romano: Dissertating, ahoy!

Usually whenever we think about gradschool we think about the switch from "doing classwork, quals, etc" to "dissertating" is a single-step process, which we call "becoming a PhD candidate" (as opposed to being a PhD *student*). In practice there are over half a dozen steps. Filing the paperwork declaring your completion of classwork, quals, etc is just the first few. (Okay, easy enough) Then there's the prospectus, for the graduate school. (The what for the who now?) Then the forming of your research committee. (Right, okay) Then the proposal. (Wait, how is this different from the other thing?) Then the proposal defense. (Um, okay, but not every department requires this?) Plus a few other steps I'm surely forgetting.

As of yesterday, I am officially finally totally completely absolutely done with all the paperwork, and can finally get back to actually working on the thesis itself!

comments

### Magnus Therning: Qt5+D-Bus+CMake, a complete example

Yesterday I started digging into Qt5 and D-Bus. I never found a complete example, so I put one together myself: https://gist.github.com/magthe/2cf7220655bd8bf431259cc7dee99f64.

### Neil Mitchell: Github Offline Issues with IssueSync

For a while I've been looking for something to download the GitHub issues for a project. I do a lot of development work on a train with no internet, so referring to the tickets offline is very useful. I've tried lot of tools, in a very wide variety of languages (Ruby, Python, Perl, Javascript, PHP) - but most of them don't seem to work - and the only one I did manage to get working only gave a curses UI.

Finally, I've found one that works - IssueSync. Installing it worked as described. Running it worked as described. I raised tickets for the author and they fixed them. I even sent a pull request and the author discussed and merged it. It downloads all your issues to Markdown files in an issues directory. I then "list" my issues using:

head -n1 -q issues/*.md | grep -v CLOSEDIt's simple and works nicely.

### accessing the RTS -M flag value from GHC.RTS.Flags

### Text.Regex.matchRegex: Success is empty?

### Documenting extensions

### Brent Yorgey: The network reliability problem and star semirings

In a previous post I defined the *network reliability* problem. Briefly, we are given a directed graph whose edges are labelled with probabilities, which we can think of as giving the likelihood of a message successfully traversing a link in a network. The problem is then to compute the probability that a message will successfully traverse the network from a given source node to a given target node.

Several commenters pointed out the connection to Bayesian networks. I think they are right, and the network reliability problem is a very special case of Bayesian inference. However, so far this hasn’t seemed to help very much, since the things I can find about algorithms for Bayesian inference are either too general (*e.g.* allowing arbitrary functions at nodes) or too specific (*e.g.* only working for certain kinds of trees). So I’m going to put aside Bayesian inference for now; perhaps later I can come back to it.

In any case, Derek Elkins also made a comment which pointed to exactly what I wanted to talk about next.

Star semirings and path independenceConsider the related problem of computing the reliability of the *single most reliable path* from to in a network. This is really just a disguised version of the shortest path problem, so one can solve it using Dijkstra’s algorithm. But I want to discuss a more general way to think about solving it, using the theory of star semirings. Recall that a *semiring* is a set with two associative binary operations, “addition” and “multiplication”, which is a commutative monoid under addition, a monoid under multiplication, and where multiplication distributes over addition and . A *star semiring* is a semiring with an additional operation satisfying . Intuitively, (though can still be well-defined even when this infinite sum is not; we can at least say that *if* the infinite sum is defined, they must be equal). If is a star semiring, then the semiring of matrices over is also a star semiring; for details see Dolan (2013), O’Connor (2011), Penaloza (2005), and Lehmann (1977). In particular, there is a very nice functional algorithm for computing , with time complexity (Dolan 2013). (Of course, this is slower than Dijkstra’s algorithm, but unlike Dijkstra’s algorithm it also works for finding shortest paths in the presence of negative edge weights—in which case it is essentially the Floyd-Warshall algorithm.)

Now, given a graph and labelling , define the adjacency matrix to be the matrix of edge probabilities, that is, . Let be the star semiring of probabilities under maximum and multiplication (where , since ). Then we can solve the single most reliable path problem by computing over this semiring, and finding the largest entry. If we want to find the actual most reliable path, and not just its reliability, we can instead work over the semiring , *i.e.* probabilities paired with paths. You might enjoy working out what the addition, multiplication, and star operations should be, or see O’Connor (2011).

In fact, as shown by O’Connor and Dolan, there are many algorithms that can be recast as computing the star of a matrix, for an appropriate choice of semiring: for example, (reflexive-)transitive closure; all-pairs shortest paths; Gaussian elimination; dataflow analysis; and solving certain knapsack problems. One might hope that there is similarly an appropriate semiring for the network reliability problem. But I have spent some time thinking about this and I do not know of one.

Consider again the simple example given at the start of the previous post:

For this example, we computed the reliability of the network to be , by computing the probability of the upper path, , and the lower path, , and then combining them as , the probability of success on either path less the double-counted probability of simultaneous success on both.

Inspired by this example, one thing we might try would be to define operations and . But when we go to check the semiring laws, we run into a problem: distributivity does not hold! , but . The problem is that the addition operation implicitly assumes that the events with probabilities and are *independent*: otherwise the probability that they both happen is not actually equal to . The events with probabilities and , however, are *not* independent. In graph terms, they represent two paths with a shared subpath. In fact, our example computation at the beginning of the post was only correct since the two paths from to were completely independent.

We can at least compute the reliability of series-parallel graphs whose terminals correspond with and :

- If consists of a single edge, return that edge’s probability.
- Otherwise, is a composition of two subgraphs, whose reliabilities we recursively compute. Then:
- If is a sequential composition of graphs, return the product of their reliabilities.
- If is a parallel composition of two graphs with reliabilities and , return .

In the second case, having a parallel composition of graphs ensures that there are no shared edges between them, so and are indeed independent.

Of course, many interesting graphs are not series-parallel. The simplest graph for which the above does not work looks like this:

Suppose all the edges have probability . Can you find the reliability of this network?

More in a future post!

ReferencesDolan, Stephen. 2013. “Fun with Semirings: A Functional Pearl on the Abuse of Linear Algebra.” In *ACM SIGPLAN Notices*, 48:101–10. 9. ACM.

Lehmann, Daniel J. 1977. “Algebraic Structures for Transitive Closure.” *Theoretical Computer Science* 4 (1). Elsevier: 59–76.

O’Connor, Russell. 2011. “A Very General Method for Computing Shortest Paths.” http://r6.ca/blog/20110808T035622Z.html.

Penaloza, Rafael. 2005. “Algebraic Structures for Transitive Closure.” http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.71.7650.

### Journal of Functional Programming - Call for PhDAbstracts

### Journal of Functional Programming - Call for PhD Abstracts

### Call for papers for David Turner's Festschrift issue ofJUCS

### Philip Wadler: Steven Pinker's The Sense of Style

I recently read Pinker's The Sense of Style, and urge you to read it too. It is chock full of practical advice on how to make your writing better. Chapter One shows you how to appreciate good writing; I never knew an obituary could be so zippy. Chapter Two explains the approach to writing called 'the classical style', which I have used my whole life without realising it. Chapter Three describes how to keep knowing what you are talking about from getting in the way of communicating clearly. Pinker is an expert on modern grammar, and Chapter Four clarifies how to parse your sentences to avoid ambiguity and employ referents correctly. Chapter Five details the mechanics of how to make a passage cohere. Chapter Six catalogues, from Pinker's position on the usage panel for the American Heritage dictionary, contentious points of diction, with his advice on how to resolve them and what points to consider when resolving them for yourself.

I recommend it highly, and doubly so if you are ever likely to write something that I will have to read.