# News aggregator

### extensible effects + classy lenses

### Functional Jobs: Software Engineer at Purple (Full-time)

Purple is a well-funded startup of about 15 people, backed by an Uber co-founder, and revolutionizing the way people get gas.

We are looking for an experienced Software Engineer who can thrive in a startup environment to help us continue to build and test our backend web service and mobile app platform. You would work closely with our small engineering team in a relatively flat organizational structure. You should be confident taking ownership of your specific piece of the product while being comfortable reaching across the full stack. We want people who are aware of latest trends and know how to adopt the most appropriate technology. We're looking for someone who is a strong advocate for the best engineering practices.

Most of our codebase is written in Clojure and ClojureScript. While prior Clojure experience is not a requirement, serious candidates must have an interest and willingness to learn Clojure as well as any technologies we are using that they may not currently be familiar with.

Minimum qualifications:

- BS degree in Computer Science, similar technical field of study or equivalent practical experience.
- Strong experience in one or more general purpose programming languages
- Strong experience in at least one scripting language (e.g., JavaScript)
- Interest and ability to learn new programming languages as needed
- Working knowledge of Git
- Ability to communicate with non-technical team members to meet product needs/goals

A big plus, but not required:

- Experience using React and React Native
- Clojure and ClojureScript experience, or:
- Experience in at least one functional programming language (Scala, OCaml, Lisp, Haskell, etc.)
- Familiarity with the JVM and related tooling

Purple is a great team! We are small, savvy, and fun. We have an office based in Westwood. We offer a competitive salary, flexible work schedule, health insurance supplement, and unlimited vacation. Come join our growing team!

Get information on how to apply for this position.

### Implement traverseMaybe in Data.Map, Data.IntMap, etc

### Well-Typed.Com: Haskell development jobs with Well-Typed

**tl;dr** *If you’d like a job with us, send your application as soon as possible.*

We are looking for several (probably two) Haskell experts to join our team at Well-Typed. This is a great opportunity for someone who is passionate about Haskell and who is keen to improve and promote Haskell in a professional context.

About Well-TypedWe are a team of top notch Haskell experts. Founded in 2008, we were the first company dedicated to promoting the mainstream commercial use of Haskell. To achieve this aim, we help companies that are using or moving to Haskell by providing a range of services including consulting, development, training, and support and improvement of the Haskell development tools. We work with a wide range of clients, from tiny startups to well-known multinationals. We have established a track record of technical excellence and satisfied customers.

Our company has a strong engineering culture. All our managers and decision makers are themselves Haskell developers. Most of us have an academic background and we are not afraid to apply proper computer science to customers’ problems, particularly the fruits of FP and PL research.

We are a self-funded company so we are not beholden to external investors and can concentrate on the interests of our clients, our staff and the Haskell community.

About the jobsOne of the roles is for a specific project with one of our clients, and requires work on-site in London. The other role is more general and not tied to a single specific project or task, and allows remote work.

Please indicate in your application whether on-site work in London is an option for you.

In general, work for Well-Typed could cover any of the projects and activities that we are involved in as a company. The work may involve:

working on GHC, libraries and tools;

Haskell application development;

working directly with clients to solve their problems;

teaching Haskell and developing training materials.

We try wherever possible to arrange tasks within our team to suit peoples’ preferences and to rotate to provide variety and interest.

Well-Typed has a variety of clients. For some we do proprietary Haskell development and consulting. For others, much of the work involves open-source development and cooperating with the rest of the Haskell community: the commercial, open-source and academic users.

Our ideal candidate has excellent knowledge of Haskell, whether from industry, academia or personal interest. Familiarity with other languages, low-level programming and good software engineering practices are also useful. Good organisation and ability to manage your own time and reliably meet deadlines is important. You should also have good communication skills. Being interested or having experience in teaching Haskell (or other technical topics) is a bonus. Experience of consulting or running a business is also a bonus. You are likely to have a bachelor’s degree or higher in computer science or a related field, although this isn’t a requirement.

Offer detailsThe offer is initially for one year full time, with the intention of a long term arrangement. For the remote role, living in England is not required. For the on-site role, you have to be allowed to work in England. We may be able to offer either employment or sub-contracting, depending on the jurisdiction in which you live.

If you are interested, please apply via info@well-typed.com. Tell us why you are interested and why you would be a good fit for Well-Typed, and attach your CV. Please indicate whether the on-site work in London is an option for you. Please also indicate how soon you might be able to start.

We are more than happy to answer informal enquiries. Contact Duncan Coutts (duncan@well-typed.com, dcoutts on IRC), Adam Gundry (adam@well-typed.com, agundry on IRC) or Andres Löh (andres@well-typed.com, kosmikus on IRC) for further information.

We will consider applications as soon as we receive them, and will try to fill the positions as soon as possible. In any case, please try to get your application to us by March 27, 2016.

### Use cases of empty type classes

### Add `take`/`drop`/`splitAt` to `Data.Map`/`Data.Set`

### implicit call stacks and calling function

### [ANN] brick-users discussion list

### Magnus Therning: Final version of JSON to sum type

After some feedback on my previous post I ended up with the following implementation.

instance FromJSON V.VersionRange where parseJSON = withObject "VersionRange" go where go o = V.thisVersion <$> o .: "ThisVersion" <|> V.laterVersion <$> o .: "LaterVersion" <|> V.earlierVersion <$> o .: "EarlierVersion" <|> V.WildcardVersion <$> o .: "WildcardVersion" <|> nullaryOp V.anyVersion <$> o .: "AnyVersion" <|> binaryOp V.unionVersionRanges <$> o .: "UnionVersionRanges" <|> binaryOp V.intersectVersionRanges <$> o .: "IntersectVersionRanges" <|> V.VersionRangeParens <$> o .: "VersionRangeParens" nullaryOp :: a -> Value -> a nullaryOp = const binaryOp f [a, b] = f a bThanks David for your suggestions.

### Tagged instances for Aeson overlapped

### Trouble on Travis CI with recent cabal versions

### 1-to-many preprocessor in stack/Cabal builds

### PolyKind for Fixed and HasResolution from Data.Fixed

### GADTs and Exponentiated Functors

### Philip Wadler: The Ask

The Scottish Government have set a target of 10% of all trips by foot or bicycle, but less than 2% of the Scottish travel budget goes to '

*active travel*' (the buzzword for getting from one place to another minus a motor). We Walk, We Cycle, We Vote and Spokes suggest you ask your candidate to pledge the following:

To raise the share of the transport budget spent on walking and cycling to 10% over the course of the next parliament.See the pages linked above for more info, including hustings you can attend to put the question to your local candidates. A don't forget to Pedal on Parliament on 23 April 2016.

### Type-level list "elem" inference

### Gabriel Gonzalez: From mathematics to map-reduce

There's more mathematics to programming than meets the eye. This post will highlight one such connection that explains the link between map-reduce and category theory. I will then conclude with some wild speculation about what this might imply for future programming paradigms.

This post assumes that you already know Haskell and explains the mathematics behind the map-reduce using Haskell concepts and terminology. This means that this post will oversimplify some of the category theory concepts in order to embed them in Haskell, but the overall gist will still be correct.

Background (Isomorphism)In Haskell, we like to say that two types, s and t, are "isomorphic" if and only if there are two functions, fw and bw, of types

fw :: s -> tbw :: t -> s

... that are inverse of each other:

fw . bw = idbw . fw = id

We will use the symbol ≅ to denote that two types are isomorphic. So, for example, we would summarize all of the above by just writing:

s ≅ tThe fully general definition of isomorphism from category theory is actually much broader than this, but this definition will do for now.

Background (Adjoint functors)Given two functors, f and g, f is left-adjoint to g if and only if:

f a -> b ≅ a -> g bIn other words, for them to be adjoint there must be two functions, fw and bw of types:

fw :: (f a -> b) -> (a -> g b)bw :: (a -> g b) -> (f a -> b)

... such that:

fw . bw = idbw . fw = id

These "functors" are not necessarily the same as Haskell's Functor class. The category theory definition of "functor" is more general than Haskell's Functor class and we'll be taking advantage of that extra generality in the next section.

Free functorsImagine a functor named g that acted more like a type-level function that transforms one type into another type. In this case, g will be a function that erases a constraint named C. For example:

-- `g` is a *type-level* function, and `t` is a *type*g (C t => t) = t

In other words, g "forgets" the C constraint on type t. We call g a "forgetful functor".

If some other functor, f is left-adjoint to g then we say that f is the "free C" (where C is the constraint that g "forgets").

In other words, a "free C" is a functor that is left-adjoint to another functor that forgets the constraint C.

Free monoidThe list type constructor, [], is the "free Monoid"

The "free Monoid" is, by definition, a functor [] that is left-adjoint to some other functor g that deletes Monoid constraints.

When we say that g deletes Monoid constraints we mean that:

g (Monoid m => m) = m... and when we say that [] is left-adjoint to g that means that:

[] a -> b ≅ a -> g b... and the type [a] is syntactic sugar for [] a, so we can also write:

[a] -> b ≅ a -> g bNow substitute b with some type with a Monoid constraint, like this one:

b = Monoid m => mThat gives us:

[a] -> (Monoid m => m) ≅ a -> g (Monoid m => m)... and since g deletes Monoid constraints, that leaves us with:

[a] -> (Monoid m => m) ≅ a -> mThe above isomorphism in turn implies that there must be two functions, fw and bw, of types:

fw :: ([a] -> (Monoid m => m)) -> (a -> m)bw :: (a -> m) -> ([a] -> (Monoid m => m))

... and these two functions must be inverses of each other:

fw . bw = idbw . fw = id

We can pull out the Monoid constraints to the left to give us these more idiomatic types:

fw :: (Monoid m => [a] -> m)) -> (a -> m)bw :: Monoid m => ( a -> m) -> ([a] -> m)

Both of these types have "obvious" implementations:

fw :: (Monoid m => [a] -> m)) -> (a -> m)fw k x = k [x]

bw :: Monoid m => (a -> m) -> ([a] -> m)

bw k xs = mconcat (map k xs)

Now we need to prove that the fw and bw functions are inverse of each other. Here are the proofs:

-- Proof #1fw . bw

-- eta-expand

= \k -> fw (bw k)

-- eta-expand

= \k x -> fw (bw k) x

-- Definition of `fw`

= \k x -> bw k [x]

-- Definition of `bw`

= \k x -> mconcat (map k [x])

-- Definition of `map`

= \k x -> mconcat [k x]

-- Definition of `mconcat`

= \k x -> k x

-- eta-reduce

= \k -> k

-- Definition of `id`

= id

-- Proof #2

bw . fw

-- eta-expand

= \k -> bw (fw k)

-- eta-expand

= \k xs -> bw (fw k) xs

-- Definition of `bw`

= \k xs -> mconcat (map (fw k) xs)

-- eta-expand

= \k xs -> mconcat (map (\x -> fw k x) xs)

-- Definition of `fw`

= \k xs -> mconcat (map (\x -> k [x]) xs)

-- map (f . g) = map f . map g

= \k xs -> mconcat (map k (map (\x -> [x]) xs))

-- ... and then a miracle occurs ...

--

-- In all seriousness this step uses a "free theorem" which says

-- that:

--

-- forall (k :: Monoid m => [a] -> m) . mconcat . map k = k . mconcat

--

-- We haven't covered free theorems, but you can read more about them

-- here: http://ttic.uchicago.edu/~dreyer/course/papers/wadler.pdf

= \k xs -> k (mconcat (map (\x -> [x]) xs)

-- This next step is a proof by induction, which I've omitted

= \k xs -> k xs

-- eta-reduce

= \k -> k

-- Definition of `id`

= idMap reduce

Let's revisit the type and implementation of our bw function:

bw :: Monoid m => (a -> m) -> ([a] -> m)bw k xs = mconcat (map k xs)

That bw function is significant because it is a simplified form of map-reduce:

- First you "map" a function named k over the list of xs
- Then you "reduce" the list using mconcat

In other words, bw is a pure "map-reduce" function and actually already exists in Haskell's standard library as the foldMap function.

The theory of free objects predict that all other functions of interest over a free object (like the free Monoid) can be reduced to the above fundamental function. In other words, the theory indicates that we can implement all other functions over lists in terms of this very general map-reduce function. We could have predicted the importance of "map-reduce purely from the theory of "free Monoids"!

However, there are other free objects besides free Monoids. For example, there are "free Monads" and "free Categorys" and "free Applicatives" and each of them is equipped with a similarly fundamental function that we can use to express all other functions of interest. I believe that each one of these fundamental functions is a programming paradigm waiting to be discovered just like the map-reduce paradigm.

### Magnus Therning: From JSON to sum type

For a while I’ve been planning to take full ownership of the JSON serialisation and parsing in cblrepo. The recent inclusion of instances of ToJSON and FromJSON for Version pushed me to take the first step by writing my own instances for all external types.

When doing this I noticed that all examples in the aeson docs use a product

data Person = Person { name :: Text , age :: Int }whereas I had to deal with quite a few sums, e.g. VersionRange. At first I struggled a little with how to write an instance of FromJSON. After quite a bit of thinking I came up with the following, which I think is fairly nice, but I’d really like to hear what others think about it. Maybe I’ve just missed a much simpler way of implementing parseJSON:

instance FromJSON V.VersionRange where parseJSON = withObject "VersionRange" go where go o = do lv <- (o .:? "LaterVersion") >>= return . fmap V.laterVersion tv <- (o .:? "ThisVersion") >>= return . fmap V.thisVersion ev <- (o .:? "EarlierVersion") >>= return . fmap V.earlierVersion av <- (o .:? "AnyVersion") >>= \ (_::Maybe [(Int,Int)]) -> return $ Just V.anyVersion wv <- (o .:? "WildcardVersion") >>= return . fmap V.WildcardVersion uvr <- (o .:? "UnionVersionRanges") >>= return . fmap toUvr ivr <- (o .:? "IntersectVersionRanges") >>= return . fmap toIvr vrp <- (o .:? "VersionRangeParens") >>= return . fmap V.VersionRangeParens maybe (typeMismatch "VersionRange" $ Object o) return (lv <|> tv <|> ev <|> uvr <|> ivr <|> wv <|> vrp <|> av) toUvr [v0, v1] = V.unionVersionRanges v0 v1 toIvr [v0, v1] = V.intersectVersionRanges v0 v1Any and all comments and suggestions are more than welcome!