News aggregator

[ANN] Budapest Haskell Hackathon 2016, 6-7th Aug 2016

haskell-cafe - Tue, 06/14/2016 - 9:00pm
Hi everybody, I'm happy to announce that our local user group will hold a Haskell Hackathon in Budapest this year (this will be the second)! We will hold it from August 6th to the 7th (Saturday & Sunday). You can find out more on the following link: We will reguraly update the site with new information. If you decide to come, please fill out the following Google Form: If you have a project, demo, or talk that you want to bring to the event please contact us, and we can talk about the details. You can find our contact info the events wiki site, or you can just contact me directly. The event will be open to people of all experience levels, from beginners to gurus. The only requisite is that you’re interested in the Haskell language, and want to hang out with us, and have a good time! Greetings from Daniel, and the other BP-HUG organizers. _______________________________________________ Haskell-Cafe mailing list Hask
Categories: Offsite Discussion

JTRES 2016, Submission Deadline Extended to July 3

General haskell list - Tue, 06/14/2016 - 8:55pm
******** ******** The paper submission deadline has been extended to ******** July 3, 2016 ******** ====================================================================== CALL FOR PAPERS The 14th Workshop on Java Technologies for Real-Time and Embedded Systems JTRES 2016 Part of the Managed Languages & Runtimes Week 2016 29 August - 2 September 2016 Lugano, Switzerland ====================================================================== Submission deadline: 3 July, 2016 Submission site: ====================================================================== Over 90% of all microprocessors are now used for real-time and embedded applications. Embedded devices are deployed on a broad diversity of distinct processor arc
Categories: Incoming News

[ANN] Budapest Haskell Hackathon 2016, 6-7th Aug 2016

General haskell list - Tue, 06/14/2016 - 8:50pm
Hi everybody, I'm happy to announce that our local user group will hold a Haskell Hackathon in Budapest this year (this will be the second)! We will hold it from August 6th to the 7th (Saturday & Sunday). You can find out more on the following link: We will reguraly update the site with new information. If you decide to come, please fill out the following Google Form: If you have a project, demo, or talk that you want to bring to the event please contact us, and we can talk about the details. You can find our contact info the events wiki site, or you can just contact me directly. The event will be open to people of all experience levels, from beginners to gurus. The only requisite is that you’re interested in the Haskell language, and want to hang out with us, and have a good time! Greetings from Daniel, and the other BP-HUG organizers. _______________________________________________ Haskell mailing list Haskel
Categories: Incoming News

Christopher Allen: How to use UUID values with Persistent and Yesod

Planet Haskell - Tue, 06/14/2016 - 6:00pm

Some people find it trickier to store UUID values in their database with Persistent or to use UUID values in a Yesod web application than is really necessary. Here I’ll share some code from my work that demonstrates some patterns in applications that use Persistent or Yesod which should make it easier.

The context for this post can be found in these two links:

Replying to: Jezen Thomas writing about using UUIDs in Yesod
Prior art: Michael Xavier on UUID columns in Persistent

Alternate title: Same as the original, but with: “and no Control.Lens needed” tacked on.

This code is adapted from stuff we’ve written at work.

Persistent / UUID integration Instances

Radioactive dumping ground for orphan instances. Adding the instances makes Persistent understand how to serialize and deserialize the UUID type. The orphans can be avoided if you use a newtype.

-- Note we're taking advantage of -- PostgreSQL understanding UUID values, -- thus "PersistDbSpecific" instance PersistField UUID where toPersistValue u = PersistDbSpecific . B8.pack . UUID.toString $ u fromPersistValue (PersistDbSpecific t) = case UUID.fromString $ B8.unpack t of Just x -> Right x Nothing -> Left "Invalid UUID" fromPersistValue _ = Left "Not PersistDBSpecific" instance PersistFieldSql UUID where sqlType _ = SqlOther "uuid" Models

This is where we actually use the UUID type in our models.

module MyCompany.DB.Models where share [mkPersist sqlSettings,mkMigrate "migration"] [persistLowerCase| User json sql=users email Email sqltype=text UniqUserEmail email uuid UUID sqltype=uuid default=uuid_generate_v4() UniqUserUuid uuid deriving Show Read Eq Typeable |]

We use the default JSON representation generated so that the format is predictable for the datatypes. I was a little queasy with this initially and it does mean we have to watch what happens to Aeson, but I believe net-net it reduces defects that reach production.

Yesod PathPiece integration

PathPiece is the typeclass Yesod uses to deserialize Text data into a more structured type, so that something like the following:

!/#Subdomain/#NumberedSlug SomeRouteR GET

could work. Here Subdomain and NumberedSlug are domain-specific types we made to represent a concept in our application in a type-safe manner. PathPiece often goes unnoticed by people new to Yesod, but it’s good to understand. For a super simple example:

newtype Subdomain = Subdomain Text deriving (Eq, Show, Read) instance PathPiece Subdomain where toPathPiece (Subdomain t) = t fromPathPiece = Just . Subdomain

The PathPiece class itself isn’t terribly complicated or interesting:

-- -- S for "Strict" class PathPiece s where fromPathPiece :: S.Text -> Maybe s toPathPiece :: s -> S.Text

To address the original post’s code, I wouldn’t have written that myself. I generally keep DB/IO stuff apart from things like forms. Partly this is because our web app repository is separate from our domain types / DB stuff repo, which sort of forces us to refactor things we might need to do more than once, or in a context that isn’t a web app. The use of applicative style and the double-lifting was not idiomatic.

Alternate title rejected for being too snarky: I told the doctor it hurts when I move my arm a certain way. The doctor told me to stop moving my arm like that.

I know this site is a bit of a disaster zone, but if you like my writing or think you could learn something useful from me, please take a look at the book I've been writing with my coauthor Julie. There's a free sample available too!

Posted on June 15, 2016

Categories: Offsite Blogs

Reminder: 10 days to submit talks to CUFP 2016

haskell-cafe - Tue, 06/14/2016 - 4:08pm
This CFP and the form for submitting presentation proposals can be found at: ---------------------------------------------------------------------- 2016 Call for Presentations Workshop for Commercial Users of Functional Programming 2016 Sponsored by SIGPLAN CUFP 2016 Co-located with ICFP 2016 Nara, Japan September 22-24 Talk Proposal Submission Deadline: 24 June 2016 The annual CUFP event is a place where people can see how others are using functional programming to solve real world problems; where practitioners meet and collaborate; where language designers and users can share ideas about the future of their favorite language; and where one can learn practical techniques and approaches for putting functional programming to work. ---------------------------------------------------------------------- Giving a CUFP Talk If you have experience using functional languages in a practical setting, we invite you to submit a proposal to give a talk at the event.
Categories: Offsite Discussion

Douglas M. Auclair (geophf): May 2016 1Liners

Planet Haskell - Tue, 06/14/2016 - 2:46pm
  • 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
    • 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 (==)
Categories: Offsite Blogs

Roman Cheplyaka: Predicting a coin toss

Planet Haskell - Tue, 06/14/2016 - 2:00pm

I flip a coin and it comes up heads. What is the probability it will come up heads the next time I flip it?

“Fifty percent,” you say. “The coin tosses are independent events; the coin doesn’t have a memory.”

Now I flip a coin ten times, and ten times in a row it comes up heads. Same question: what is the probability it will come up heads the next time?

You pause for a second, if only because you are not used to getting heads ten times in a row.

But, after some hesitation, you convince yourself that this is no different from the first experiment. The coin still has got no memory, and the chances are still 50-50.

Or you become suspicious that something is not right with the coin. Maybe it is biased, or maybe it has two heads and no tails. In that case, your answer may be something like 95% for heads, where the remaining 5% account for the chance that the coin is only somewhat biased and tails are still possible.

This sounds paradoxical: coin tosses are independent, yet the past outcomes influence the probability of the future ones. We can explain this by switching from frequentist to Bayesian statistics. Bayesian statistics lets us model the coin bias (the probability of getting a single outcome of heads) itself as a random variable, which we shall call \(\theta\). It is random simply because we don’t know its true value, and not because it varies from one experiment to another. Consequently, we will update its probability distribution after every experiment because we gain more information, not because it affects the coin itself.

<figure> </figure>

Let \(X_i\in\{H,T\}\) be the outcome of \(i\)th toss. If we know \(\theta\), we automatically know the distribution of \(X_i\):


As before, the coin has no memory, so for any given \(\theta\), the tosses are independent: \(p(X_i \wedge X_j|\theta)=p(X_i|\theta)p(X_j|\theta)\). But they are independent only when conditioned on \(\theta\), and that resolves the paradox. If we don’t assume that we know \(\theta\), then \(X\)s are dependent, because the earlier observations affect what we know about \(\theta\), and \(\theta\) affects the probability of the future observations.

A model with conditionally independent variables is called a Bayesian network or probabilistic graphical model, and it can be represented by a directed graph as shown on the right. The arrows point from causes to effects, and the absence of an edge indicates conditional independence.

Based on our evidence of 10 heads in a row, the Bayes’ theorem lets us estimate the distribution of \(\theta\). All we need is a prior distribution – what did we think about the coin before we tossed it?

For coin tossing and other binary problems, it is customary to take the Beta distribution as the prior distribution, as it makes the calculations very easy. Often such choice is justified, but in our case it would be a terrible one. Almost all coins we encounter in our lives are fair. To make the beta distribution centered at \(\theta=0.5\) and low variance, we would need to set its parameters, \(\alpha\) and \(\beta\), to large equal numbers. The resulting distribution would assign non-trivial probability only to low deviations from \(\theta=0.5\), and the distribution would be barely affected by our striking evidence.

<figure> </figure>

Instead, let’s engineer our prior distribution from scratch. Double-sided coins may be rare in everyday life, but they are easy to buy on eBay. When someone approaches us out of the blue and starts flipping coins, there’s a fair chance they’ve got one of those. Still, we believe in humanity, so let’s assign a point probability of just \(1\%\) to \(\theta=0\) and \(\theta=1\). What about biased coins, such as coins with \(\theta=0.83\)? Turns out they are unlikely to exist. Nevertheless, the Bayesian statistics teaches to be reluctant to assign zero probabilities to events, since then no amount of evidence can prove us wrong. So let’s take \(0.1\%\) and spread it uniformly across the interval \([0;1]\). The remaining \(97.9\%\) will be the probability of a fair coin.

Formally, our prior distribution over \(\theta\) can be specified by its probability density as

\[ p(\theta)=0.979\delta(\theta-0.5)+0.01\delta(\theta)+0.01\delta(\theta-1)+0.001, \]

where \(\delta\) is the Dirac delta function used to specify point probabilities.

Let \(D\) refer to the event that \(X_i=H\), \(i=1,2,\ldots,10\). Then \(p(D|\theta)=\theta^{10}\). By Bayes’ theorem,

\[ p(\theta|D)=\frac{p(D|\theta)p(\theta)}{\int_0^1 p(D|\theta)p(\theta)d\theta} = \frac{\theta^{10}p(\theta)}{\int_0^1 \theta^{10}p(\theta)d\theta}. \]

Now we need to do a bit of calculation by hand:

\[ \begin{multline} \int_0^1 \theta^{10}p(\theta)d\theta=0.979\cdot0.5^{10}+0.01\cdot 1^{10}+0.01 \cdot 0^{10} + 0.001\int_0^1 \theta^{10}d\theta \\ = 9.56\cdot 10^{-4} + 0.01 + 9.09\cdot 10^{-5}=0.0110; \end{multline} \] \[ p(\theta|D)=0.087\delta(\theta-0.5)+0.905\delta(\theta-1)+0.091\theta^{10}. \]

Thus, we are \(90.5\%\) sure that the coin is double-headed, but we also allow \(8.7\%\) for pure coincidence and \(0.8\%\) for a biased coin.

<figure> </figure> <figure> </figure>

Now back to our question: how likely is it that the next toss will produce heads?

\[ \begin{multline} p(X_{11}=H|D) = \int_0^1 p(X_{11}=H|D,\theta)p(\theta|D)d\theta = \int_0^1 \theta \, p(\theta|D)d\theta \\ = 0.087\cdot 0.5+0.905\cdot 1+0.091\cdot \int_0^1\theta^{11}d\theta = 0.956. \end{multline} \]

Very likely indeed. Notice, by the way, how we used the conditional independence above to replace \(p(X_{11}=H|D,\theta)\) with \(p(X_{11}=H|\theta)=\theta\).

Bayesian statistics is a powerful tool, but the prior matters. Before you reach for the conjugate prior, consider whether it actually represents your beliefs.

A couple of exercises:

  1. How does our prior distribution change after a single coin toss (either heads or tails)?
  2. How does our prior distribution change after ten heads and one tails?
Categories: Offsite Blogs

Package takeover (also: the future of Netwire)

haskell-cafe - Tue, 06/14/2016 - 1:30pm
Hi everybody, I'd like to take over the following Hackage packages with my account named [esz]: * acme-schoenfinkel, * cascading, * continue, * contstuff-monads-tf, * contstuff-transformers, * contstuff, * dnscache, * fastirc, * ihttp, * instinct, * ismtp, * netlines, * netwire, * quickset, * web-page, * webwire, * yesod-tableview. These are actually already mine, but because my old account has become practically inaccessible, I'm now following the official [takeover procedure], asking myself whether I'm okay with that. =) After the takeover, I'm going to deprecate the following packages, unless someone would like to take over maintenance: * cascading: Clay is more comprehensive and easier to use. * contstuff*: Childhood experiments, because after writing a monad tutorial of course you must write an mtl replacement. * dnscache: Useful library, but needs maintenance. * fastirc: irc is reasonably efficient now (it used to be a String parser). * ihttp
Categories: Offsite Discussion

Philip Wadler: Naomi Klein: The Best is Yet to Come

Planet Haskell - Tue, 06/14/2016 - 9:22am

Amidst all the bad news, Naomi Klein shines a ray of light.
Taken together, the evidence is clear: The left just won. Forget the nomination—I mean the argument. Clinton, and the 40-year ideological campaign she represents, has lost the battle of ideas. The spell of neoliberalism has been broken, crushed under the weight of lived experience and a mountain of data.

What for decades was unsayable is now being said out loud—free college tuition, double the minimum wage, 100 percent renewable energy. And the crowds are cheering. With so much encouragement, who knows what’s next? Reparations for slavery and colonialism? A guaranteed annual income? Democratic worker co-ops as the centerpiece of a green jobs program? Why not? The intellectual fencing that has constrained the left’s imagination for so long is lying twisted on the ground. ...

Looking beyond this election cycle, this is actually good news. If Sanders could come this far, imagine what a left candidate who was unburdened by his weaknesses could do. A political coalition that started from the premise that economic inequality and climate destabilization are inextricable from systems of racial and gender hierarchy could well build a significantly larger tent than the Sanders campaign managed to erect.

And if that movement has a bold plan for humanizing and democratizing new technology networks and global systems of trade, then it will feel less like a blast from the past, and more like a path to an exciting, never-before-attempted future. Whether coming after one term of Hillary Clinton in 2020, or one term of Donald Trump, that combination—deeply diverse and insistently forward-looking—could well prove unbeatable.
Categories: Offsite Blogs

Philip Wadler: Scientists for EU

Planet Haskell - Tue, 06/14/2016 - 9:06am

Scientists for EU wrote a cogent letter explaining how the EU advances UK science, and how UK science advantages the UK. You can sign it here.
Please read this letter, add your name and share this link with other scientists.
Scientific advance and innovation are critically dependent on collaboration. To remain a world-leading science nation, we must be team players.
The EU leads the world in science output, is beating the US in science growth – and is rapidly increasing investment in research. The EU is a science superpower. Our place in this team has boosted our science networking, access to talent, shared infrastructure and UK science policy impact. The economy of scale streamlines bureaucracy and brings huge added value for all. International collaborations have 40% more impact than domestic-only research.
Strong science is key for our economy and quality of life. It creates a virtuous cycle, leveraging investment from industry, raising productivity and creating high-value jobs for our future. In fact, 20% of UK jobs currently rely on some science knowledge. Science brings better medicines, cleaner energy, public health protections, a safer environment, new technologies and solutions to global challenges.
If we leave the EU, the UK will lose its driving seat in this world-leading team. Free-flow of talent and easy collaboration would likely be replaced by uncertainty, capital flight, market barriers and costly domestic red-tape. This would stifle our science, innovation and jobs.
It is no surprise that a recent survey showed 93% of research scientists and engineers saying the EU is a “major benefit” to UK research. The surprise is that many voters are still unaware that UK science and its benefits would be demoted by a vote to leave.
We, the undersigned, urge you to seriously consider the implications for UK science when you vote in the referendum on UK membership of the EU.
Categories: Offsite Blogs

Philip Wadler: A week of cycling ideas from Copenhagen

Planet Haskell - Tue, 06/14/2016 - 8:26am

People for Bikes is visiting Copenhagen to learn about its famous cycling infrastructure. A week of stories is archived here, including The Great Copenhagen Loading Zone Compromise and How bikes make Copenhagen's neighbourhood business districts thrive.

Categories: Offsite Blogs

CUFP 2016 Call For Tutorials

haskell-cafe - Tue, 06/14/2016 - 7:50am
Hi all, The Commercial Users of Functional Programming (CUFP) 2016 has its Call for Tutorials open for submission. CUFP 2016 is being held in the historic city of Nara, Japan. The conference is devoted to showcase the state of the art of Functional Programming on industrial settings. This conference is co-located with the International Conference of Functional Programming (ICFP). We're looking for tutors that would like to host workshops on on the following themes: - Introductions to functional programming languages. In the past we have had sessions of Clojure, Erlang, F#, F*, Haskell, ML, OCaml, Scala, Scheme and others. - Advanced programming languages, concepts and applications (e.g. Lens, Liquid-Haskell, Agda, Idris, etc.) - Applying functional programming in particular areas, including Web, high-performance computing, finance. - Tools and techniques supporting state of the art functional programming. In the past we have had tutorials on QuickCheck, Elm and others. - Theory. Type theory, categor
Categories: Offsite Discussion

LOPSTR'16: Final Call for Papers and *Deadline Extension*

General haskell list - Mon, 06/13/2016 - 9:24pm
[ Please distribute, apologies for multiple postings. ] ====================================================================== LOPSTR 2016: Final Call for Papers / Deadline Extension ====================================================================== 26th International Symposium on Logic-Based Program Synthesis and Transformation LOPSTR 2016 Edinburgh, UK, September 6-8, 2016 (co-located with PPDP 2016 and SAS 2016) ====================================================================== NEW DEADLINES: Abstract submission (extended): June 20, 2016 Paper/Extended abstract submission (extended): June 27, 2016 ====================================================================== INVITED SPEAKERS: Francesco Logozzo (Facebook, USA) [jointly with PPDP] Greg Morrisett (Cornell University, USA) [jointly with PPDP] Martin Vec
Categories: Incoming News

Two Lectureships (Assistant Professorships) at St Andrews

General haskell list - Mon, 06/13/2016 - 10:09am
We have two vacancies at St Andrews. These are fixed term (3 years), but we are likely to have permanent positions in time. We are looking for good researchers. I would welcome applications from the functional programming community. The deadline is June 29th. See: for details. Best Wishes, Kevin PS If you are sending mail to kh< at >, you may get a bounce message. I should still have received your email despite the error message. For future mail, the best and most reliable email address to use is kevin< at > -please update your address book. -------- Kevin Hammond, Professor of Computer Science, University of St Andrews T: +44-1334 463241 F: +44-1334-463278 W: In accordance with University policy on electronic mail, this email reflects the opinions of the individual concerned, may contain confidential or copyright information that sho
Categories: Incoming News

CMM-to-ASM: Register allocation wierdness

glasgow-user - Sun, 06/12/2016 - 7:38pm
Hi, I am implementing unicode normalization in Haskell. I challenged myself to match the performance with the best C/C++ implementation, the best being the ICU library. I am almost there, beating it in one of the benchmarks and within 30% for others. I am out of all application level tricks that I could think of and now need help from the compiler. I started with a bare minimum loop and adding functionality incrementally watching where the performance trips. At one point I saw that adding just one 'if' condition reduced the performance by half. I looked at what's going on at the assembly level. Here is a github gist of the assembly instructions executed in the fast path of the loop, corresponding cmm snippets and also the full cmm corresponding to the loop: I have annotated the assembly code with labels matching the corresponding CMM. With the addition of another "if" condition the loop which was pretty simple till now suddenly got
Categories: Offsite Discussion

[ANN] aivika-lattice-0.1

haskell-cafe - Sun, 06/12/2016 - 2:35pm
Hi Cafe, I’m glad to introduce a complete new module aivika-lattice [1] for the Aivika simulation library. It allows running nested discrete event simulations within lattice. If the naive approach implies that traversing the nested simulation nodes has an exponential complexity, then the lattice approach gives us a quadratical growth. This is a key feature, which makes the traversing a computationally feasible task even for a large size lattice. It can be useful for financial modeling, for instance. The model can be divided into two different parts. The first part is a discrete event simulation that branches in the lattice nodes. Within this simulation, we can update a mutable reference that can be observed in another part of the model. For example, such a reference can store a value of the modeled interest rate, or stock price, or exchange rate. It is important that the first part is forward traversing, when the time increases from the past to the future. The first part can even include discontinuous p
Categories: Offsite Discussion

Philip Wadler: David Turner Festschrift

Planet Haskell - Sun, 06/12/2016 - 1:12pm

Your chance to submit to a Festschrift for David Turner.
Categories: Offsite Blogs

Philip Wadler: A busy summer

Planet Haskell - Sun, 06/12/2016 - 11:59am
I'll be speaking at the following events.
Hope to see you at one of these!
Categories: Offsite Blogs

left to right pipeline of functions

haskell-cafe - Sun, 06/12/2016 - 6:46am
Hi, I am learning about monads, and this question came to mind: is there a way to have a sequence of functions left to right like so: g = return 2 >>= \n -> return (n + 1) >>= \n -> return (n + 3) Either: some kind of generic monad that makes this legal, or some way to do this without monad (i.e., without the "returns").
Categories: Offsite Discussion