Rúnar Bjarnason's Blog, page 2
February 15, 2015
Free Monoids and Free Monads
In a series of old posts, I once talked about the link between lists and monoids, as well as monoids and monads. Now I want to talk a little bit more about monoids and monads from the perspective of free structures.
List is a free monoid. That is, for any given type A, List[A] is a monoid, with list concatenation as the operation and the empty list as the identity element.
1
2
3
4
def freeMonoid[A]: Monoid[List[A]] = new Monoid[List[A]] {
def unit = Nil
def op(a1: List[A], a2: List[A]) = a1 ++ a2
}
B...
Free Monads and the Yoneda Lemma
Last week I gave a talk on Purely Functional I/O at Scala.io in Paris. The slides for the talk are available here. In it I presented a data type for IO that is supposedly a “free monad”. But the monad I presented is not exactly the same as scalaz.Free and some people have been asking me why there is a difference and what that difference means.
IO as an application of Free
The Free monad in Scalaz is given a bit like this:
1
2
3
sealed trait Free[F[_],A]
case class Return[F[_],A](a: A) extends Free[F...
Monoid Morphisms, Products, and Coproducts
Today I want to talk about relationships between monoids. These can be useful to think about when we’re developing libraries involving monoids, and we want to express some algebraic laws among them. We can then check these with automated tests, or indeed prove them with algebraic reasoning.
This post kind of fell together when writing notes on chapter 10, “Monoids”, of Functional Programming in Scala. I am putting it here so I can reference it from the chapter notes at the end of the book.
Mono...
At Long Last
In early September 2014, we published Functional Programming in Scala. It is now available from all major booksellers, and from the publisher at manning.com/bjarnason. It’s available as a beautiful paper book, on Kindle and other e-book readers, and as a PDF file.
I just want to share my personal story of how this book came to exist. A much shorter version of this story became the preface for the finished book, but here is the long version.
Around 2006 I was working in Austin and coming up on m...
Taking a Break From Twitter
Today I disabled my Twitter account. Probably only temporarily, but we’ll see. This is just a quick note to let everyone know that I’m not leaving Twitter because of anything specific. It’s not that you said or did anything wrong. I just find that it’s becoming an energy sink for me. I’m putting Twitter away as a measure to control my focus, and to better control what information I consume and produce.
Hopefully this means that I will post more here when I have something interesting to share....
A Better Reading List With Mathematica
Like a lot of people, I keep a list of books I want to read. And because there are a great many more books that interest me than I can possibly read in my lifetime, this list has become quite long.
In the olden days of brick-and-mortar bookstores and libraries, I would discover books to read by browsing shelves and picking up what looked interesting at the time. I might even find something that I knew was on my list. “Oh, I’ve been meaning to read that!”
The Internet changes this dynamic dramat...
February 9, 2015
New Beginnings
I have not seriously updated the old Apocalisp blog for quite some time. Mostly this is due to the fact that I have been spending all of my creative time outside of work on writing a book. It’s also partly that putting a post up on WordPress is a chore. It’s like building a ship in a bottle.
So I have decided to make posting really easy for myself by hosting the blog on GitHub. I am using a dead-simple markdown-based framework called Octopress. With this setup I can very easily write a new pos...
What purity is and isn't
A lot of discussion about “purity” goes on without participants necessarily having a clear idea of what it means exactly. Such discussion is generally unhelpful and distracting.
What purity is
The typical definition of purity (and the one we use in our book) goes something like this:
An expression e is referentially transparent if for all programs p, every occurrence of e in p can be replaced with the result of evaluating e without changing the result of evaluating p.
A function f is pure if the...
Machines and stream processing
I gave a talk on “Machines” and stream processing in Haskell and Scala, to the Brisbane Functional Programming Group at Microsoft HQ in December 2012. A lot of people have asked me for the slides, so here they are:
The preëmptive answer to the usual follow-up question is that the talk was not recorded.
Free monoids and free monads
In a series of old posts, I once talked about the link between lists and monoids, as well as monoids and monads. Now I want to talk a little bit more about monoids and monads from the perspective of free structures.
List is a free monoid. That is, for any given type A, List[A] is a monoid, with list concatenation as the operation and the empty list as the identity element.
1
2
3
4
def freeMonoid[A]: Monoid[List[A]] = new Monoid[List[A]] {
def unit = Nil
def op(a1: List[A], a2: List[A]) = a1 ++ a2
}
B...