Monadic Design Patterns For The Web. Haskell and Vagrant's Middleware. The 26th is the first day of instruction in the first academic year of my PhD in Computer Science at UCLA.
I have a two year old daughter, an incredibly supportive wife, and I just turned 30. Unsurprisingly, I've been asked many times why I want to get a PhD and I rarely get a chance to explain my thinking fully. This post is both a detailed account of my reasons and a counterpoint to the popular opinion that there isn't much value in higher education in Computer Science.
Why Bother? Any confusion or surprise over my decision to go back to school can generally be reduced to a simple idea: the success I would otherwise have while getting my PhD is of greater absolute value than the education. This comes in many reasonable forms. In some cases there is a subtle suggestion that academia and higher education are losing their value. In each case, I'm consistently left wanting more time to describe my thinking and the personal experiences that landed me in a PhD program. Career Path On Academia. Operational semantics for monads « Random Agent. While randomly browsing around on Planet Haskell I’ve found a post on Heinrich Apfelmus‘ blog about something called “operational semantics” for monads.
Found it very iluminating. Basically it’s a form to implement monads focusing not on defining the bind and return operators, but on what the monad is really supposed to do. It’s a view where a monad define a Domain Specific Language, that must be interpreted in order to cause it’s effects. It seems to me it’s exactly what is implemented in the monadprompt (Control.Monad.Prompt) package, although I’m not sure. > {-# LANGUAGE GADTs #-}> import Control.Monad> import Data.Map (Map, fromList, unionWith) Monads, a Field Guide. The Comonad.Reader " Monads for Free. Today I'd like to talk about free monads.
The free monad of a functor is a monad that is uniquely determined by the functor (up to isomorphism, etc), given by: Usually the above is written up using a newtype around a sum (Either) so you can write it using nice point-free style, but I think this makes for clearer introduction this way. The idea is that you take the functor and recursively fold it in upon a choice of either itself or a naked variable. instance Functor f => Functor (Free f) where fmap f (Roll x) = Roll $ fmap (fmap f) x fmap f (Return x) = Return (f x) Now, we wouldn't call it the free 'monad' without reason. Instance Functor f => Monad (Free f) where return = Return Return m >>= k = k m -- given by: return m >>= k = k m Roll m >>= k = Roll $ fmap (>>= k) m (>>=) substitutes 'subtrees' for all of the naked variables in our monad.
We can define a form of catamorphism for the free monad: Lets motivate this with an example. We can steal a nice typeclass from Laemmel and Rypacek: Free Monads In Haskell. Did you know that you can actually generate a monad automatically given any endofunctor?
This is the free monad of that functor. How do we perform this magic trick? Quite simple, everything follows from this data type: data FreeM f a = Return a | Bind (f (FreeM f a)) In this, the f parameter is just the functor we are going to build a monad for, and a is the type of the contents of a FreeM value. If you want to build up some intuition about this definition, you can think of it as specifying values that consist of an actual a (in a Return constructor) but nested within a finite number of functor applications.
As another aside, you might like to know that actually Haskell would let you create an infinite stack of functors fairly straightforwardly, since all its data declarations are actually really co-data declarations. Having got this far through the post, you won't be surprised to learn that we can make this definition into a functor itself. That Bind case looks pretty scary, doesn't it?