News aggregator

does anyone know what awelon is?

Haskell on Reddit - Sun, 04/19/2015 - 12:55am

After reading, it's clear to me that this blog has a lot of good ideas.

But after reading several posts, and Mr. or Mrs. dmbarbour's repository, I really have no idea what "the next step" is, WRT global shared mutable state and stuff. like any libraries that expose this model of programming in Haskell. Or a post with more concrete examples.

The author seems to be working on awelon (written in Haskell), a programming... Language? Environment?

I may be misunderstanding, but something like: "the global store is memcached or the file system or whatever, here are some primitives and combinators for accessing different parts of the global store, don't define functions the normal way but instead do it in this special way to minimize local state" or maybe "here is this new type, it's like a Reader or a State, and you want every function you define to have it as its return type, but somehow it's not a huge pain because of this novel contribution". etc.

anyways, if anyone has any insight, that would be appreciated.

submitted by sambocyn
[link] [7 comments]
Categories: Incoming News

What Haskell web framework do you use and why?

Haskell on Reddit - Sat, 04/18/2015 - 5:43pm

I'd quite like to learn how to make Haskell powered websites and I'm having trouble deciding which framework to use. Thanks in advance

submitted by destructaball
[link] [91 comments]
Categories: Incoming News

How to stay compatible with older ghc?

Haskell on Reddit - Sat, 04/18/2015 - 5:37pm

My current approach for backwards compatibility with older ghc/base versions is to have a custom prelude, that contains some CPP and other nastiness, for example: I was wondering if there's a cleaner solution...

submitted by sinelaw
[link] [9 comments]
Categories: Incoming News

dependency issues on a new install of haskell-platform 2014.2.0.0 64bit on OSX

haskell-cafe - Sat, 04/18/2015 - 5:58am
so I keep seeing failures in some modules, but if i install them by hand things get resolved. How do i get cabal to do this for me? so the dependencies: criterion -> monad-par- -> parallel- which fails but installing parallel- unravels the broken dependency chain. Below is the output: cabal: Error: some packages failed to install: criterion- depends on monad-par- which failed to install. monad-par- failed during the building phase. The exception was: ExitFailure 1 statistics- depends on monad-par- which failed to install. anatolys-MacBook:rbm anatolyy$ cabal install monad-par Resolving dependencies... Configuring monad-par- Building monad-par- Failed to install monad-par- Last 10 lines of the build log ( /Users/anatolyy/.cabal/logs/monad-par- ): Building monad-par- Preprocessing library monad-par- <command line>: cannot satisfy -package-id parallel-
Categories: Offsite Discussion

all for Contributions - Haskell Communities and Activities Report, May 2015 edition (28th edition)

General haskell list - Sat, 04/18/2015 - 3:04am
Dear all, We would like to collect contributions for the 28th edition of the ============================================================ Haskell Communities & Activities Report Submission deadline: 17 May 2015 (please send your contributions to hcar at, in plain text or LaTeX format) ============================================================ This is the short story (one extra point to the story added from previous editions): * If you are working on any project that is in some way related to Haskell, please write a short entry and submit it. Even if the project is very small or unfinished or you think it is not important enough --- please reconsider and submit an entry anyway! * If you are interested in an existing project related to Haskell that has not previously been mentioned in the HCAR, please tell us, so that we can contact the project leaders
Categories: Incoming News

Typeclasses and exception safety

Haskell on Reddit - Fri, 04/17/2015 - 9:57pm

Almost a year into Haskell as a hobbyist I have two general thoughts that I think are related and I wanted to get some opinions on them.

Having now written it out, this seems a bit rant like and it's kind of long. The TL;DR is: (1) we don't seem to have a generalized typeclass for some things, e.g. no MonadMaybe, and (2) when it comes to IO I can compile code that will crash at runtime due to an exception, when even Java won't let that happen. Finally (3) is my understanding correct / is there some way of addressing this?

Generalized typeclasses

I recently noticed that there are two general "types" of Monads (with a whole bunch of exceptions and variations). The first is SomeMonad a that is specifically about the a. A Tree a, Maybe a, [a], ST s a etc. While the second is a Monad to which the a can often be superfluous, Reader r (), State s (), Writer w () etc. With some that skirt the line (IO, Iter, Rand). I'm sure there's some formal Category theoretic way of saying that.

For the most part when using one of the second type, they tend to be implemented in terms of a Typeclass e.g. MonadReader or MonadState. This makes using them in a transformer stack very easy without having to worry about littering the code with lifts.

With FTP we seem to have done that with Collections. But we don't really do it with anything else. Suppose you have a Transformer stack MaybeT m a, and inside of that stack you use Data.Map.lookup which returns Maybe a, then you would have to run MaybeT . return over it to get it into MaybeT.

I figured that with EitherT I could use MonadThrow with return and throwM as a generalizer. I discovered however that at some point I'd need to catch the exception with catch ea (\e -> left e). Which left me wondering why there isn't a generalized typeclass for the likes of Either and Maybe. And secondly, why the compiler wasn't telling me that an exception hadn't been caught.

Exception Safety

One of the great things about Java was how it forced exception handling. If you call a method that throws an exception, you either have to handle it or your method has to throw the same exception. Which means that somewhere along the call stack you must handle it.

To me one of Java's biggest downfalls is that this isn't more rigid. Lookup functions for example don't tended not to throw a NullPointerException and use of Optional certainly wasn't very wide spread. But because exceptions either had to be handled or bubbled their way up the call stack, when they were present you could always choose when you wanted to address them.

I realised today that Haskell doesn't necessarily handle this very well when it comes to IO. I am able to compile a program that will crash on an exception.

I was looking at the async package today. The first thing I noticed was the more specialized type signature async :: IO a -> IO (Async a) instead of a generalized async :: MonadIO m => m a -> m (Asnyc a). Then I noticed that the type signature waitCatch :: Async a -> IO (Either SomeException a) which also forces specialization of the error handling to Either. But even if I use waitCatch is there some asynchronous exception that might be thrown in the parent? Can I get any guarantees from the type signature?

More to the point, I can compile my program using just wait and not handle any exceptions downstream at all. If I make a Map with known values the compiler won't let me get away with not handling null pointer exceptions (or pretending they don't exist with fromJust). But the compiler is perfectly happy to let me make a request to an external server that may timeout, give a bad response, or cause some other exception.

How to address it?

Is there some way the compiler can tell me when a process will crash at runtime because an exception hasn't been handled? Obviously I don't want my code littered with try/catch/finally blocks. But even that might be better than deferring the issue to runtime.

Hopefully not too much of a rant. Almost a year into Haskell now and this is the first time this occurred to me. Perhaps I just have some misunderstanding that could be addressed.

submitted by TheCriticalSkeptic
[link] [15 comments]
Categories: Incoming News


General haskell list - Fri, 04/17/2015 - 9:40pm
[apologies for any cross-posting] Call for Papers --------------------------------------------------------------------------- 13th International Conference on Logic Programming and Non-monotonic Reasoning LPNMR 2015 Lexington, KY, USA September 27-30, 2015 (Collocated with the 4th Conference on Algorithmic Decision Theory 2015) --------------------------------------------------------------------------- AIMS AND SCOPE LPNMR 2015 is the thirteenth in the series of international meetings on logic programming and non-monotonic reasoning. LPNMR is a forum for exchanging ideas on declarative logic programming, non-monotonic reasoning, and knowledge representation. The aim of the conference is to facilitate interactions between researchers and practitioners interested in the design and
Categories: Incoming News

How to instance Applicative and Alternative for State-like monadic types

Haskell on Reddit - Fri, 04/17/2015 - 7:43pm

I've just returned to Haskell after a fair break, during which I e.g. learned Prolog. I've forgotten a fair bit, but I thought I still had the key concepts. In my revision, I just ran into something that surprised so I'm hoping for some feedback to make sure I haven't got it wrong.

I have a non-deterministic State-like monad - one of my earliest learning examples, obviously based on parser combinators, which actually gets used a fair bit, though obviously it has problems. With the Applicative-Monad proposal, I decided to stop ignoring warnings and add the instances for Applicative and Alternative. First, I had to revise how the classes relate to each other.

What I've come up with is that the functions for Applicative and Alternative never touch the state - it's threaded through but otherwise left alone. These functions do their work in the return value.

Is that sane? Or have I made a messed up.

Relevant extracts from this code (just the minimum needed for the instances)...

newtype NDState s r = NDState { runNDState :: s -> [(r, s)] } ndsBind :: NDState s r1 -> (r1 -> NDState s r2) -> NDState s r2 ndsBind (NDState u) fv = NDState (\s -> [(r2, s2) | (r1, s1) <- u s , (NDState v) <- [fv r1] , (r2, s2) <- v s1 ]) instance Monad (NDState s) where return x = NDState (\s -> [(x, s)]) (>>=) = ndsBind instance MonadPlus (NDState s) where mzero = NDState (\_ -> []) mplus (NDState u) (NDState v) = NDState (\s -> (u s) ++ (v s)) instance MonadState s (NDState s) where get = NDState (\s -> [(s, s)]) put s = NDState (\_ -> [((), s)]) state f = NDState (\s -> [f s ]) instance Functor (NDState s) where fmap f (NDState u) = NDState (\s -> [(f r1, s1) | (r1, s1) <- u s]) instance Applicative (NDState s) where pure x = NDState (\s -> [(x, s)]) (NDState f) <*> (NDState x) = NDState (\s -> [(f1 x1, s2) | (f1, s1) <- f s, (x1, s2) <- x s1]) instance Alternative (NDState s) where empty = NDState (\_ -> []) (NDState u) <|> (NDState v) = NDState (\s -> (u s) ++ (v s)) submitted by ninereeds314
[link] [10 comments]
Categories: Incoming News

Existentially/universally quantified types

Haskell on Reddit - Fri, 04/17/2015 - 7:22pm

TL;DR: Soliciting more explanations of existential quantification, please!

The GHC User Guide states that an existentially quantified type such as

data Foo = forall a. MkFoo a

is called so (despite the forall) because of MkFoo :: forall a. a -> Foo's equivalence to

MkFoo :: (exists a. a) -> Foo

(thus precluding the need for a separate exists keyword). Also, this lecture and some other Stack Overflow answers have shown that existential types can be encoded as universal types:

data E = forall x. E x (x -> String)

is equivalent to

newtype U = U (forall w. (forall x. (x, x -> String) -> w) -> w)

Oleg's lecture even includes the following derivation:

exists x. P x <=> ~~(exists x. P x) <=> ~(forall x. ~(P x)) <=> ~(forall x. P x -> _|_) <=> (forall x. P x -> _|_) -> _|_

Yet still, despite all of these excellent resources, something isn't clicking. In particular, the type U above is somewhat impenetrable, and I don't quite see how the logical derivation matches up with the Haskell types. I definitely don't feel like I could explain any of this to a child, which means I obviously don't understand it well :)

Could someone please pellucidly explain your understanding of existential quantification, universal quantification, their relation to the Curry-Howard isomorphism, and their general role in the Haskell programmer's toolbox? For what it's worth, I'm aware of the so-called existential typeclass antipattern, but I've also seen a fascinating use of existential types in combination with GADTs to write a well-typed insert function for 2-3 trees here. It seems like there's a lot of power here, which I personally have trouble finding uses for, and I'd like to level up after a year or so of banging my head against a wall over this stuff =)

Thank you very much!

submitted by MitchellSalad
[link] [15 comments]
Categories: Incoming News

Roman Cheplyaka: Safe concurrent MySQL access in Haskell

Planet Haskell - Fri, 04/17/2015 - 2:00pm

mysql, Bryan O’Sullivan’s low-level Haskell bindings to the libmysqlclient C library, powers a few popular high-level MySQL libraries, including mysql-simple, persistent-mysql, snaplet-mysql-simple, and groundhog-mysql.

Most users do not suspect that using mysql as it stands concurrently is unsafe.

This article describes the issues and their solutions.

Issue 1: unsafe foreign calls

As of version, mysql marks many of its ffi imports as unsafe. This is a common trick to make these calls go faster. In our case, the problem with unsafe calls is that they block a capability (that is, an OS thread that can execute Haskell code). This is bad for two reasons:

  1. Fewer threads executing Haskell code may result in less multicore utilization and degraded overall performance.
  2. If all capabilities get blocked executing related MySQL statements, they may deadlock.

Here’s a demonstration of such a deadlock:

{-# LANGUAGE OverloadedStrings #-} import Database.MySQL.Simple import Control.Concurrent import Control.Concurrent.STM import Control.Applicative import Control.Monad import Control.Exception main = do tv <- atomically $ newTVar 0 withConn $ \conn -> do mapM_ (execute_ conn) [ "drop table if exists test" , "create table test (x int)" , "insert into test values (0)" ] forM_ [1..2] $ \n -> forkIO $ withConn $ \conn -> (do execute_ conn "begin" putStrLn $ show n ++ " updating" execute_ conn "update test set x = 42" putStrLn $ show n ++ " waiting" threadDelay (10^6) execute_ conn "commit" putStrLn $ show n ++ " committed" ) `finally` (atomically $ modifyTVar tv (+1)) atomically $ check =<< (>=2) <$> readTVar tv where withConn = bracket (connect defaultConnectInfo) close

If you run this with stock mysql-, one capability (i.e. without +RTS -Nx), and either threaded or non-threaded runtime, you’ll see:

1 updating 1 waiting 2 updating 1 committed test: ConnectionError { errFunction = "query", errNumber = 1205, errMessage = "Lock wait timeout exceeded; try restarting transaction"}

Here’s what’s going on:

  1. Both threads are trying to update the same row inside their transactions;
  2. MySQL lets the first update pass but blocks the second one until the first update committed (or rolled back);
  3. The first transaction never gets a chance to commit, because it has no OS threads (capabilities) to execute on. The only capability is blocked waiting for the second UPDATE to finish.

The solution is to patch mysql to mark its ffi calls as safe (and use the threaded runtime). Here’s what would happen:

  1. To compensate for the blocked OS thread executing the second UPDATE, the GHC runtime moves the capability to another thread (either fresh or drawn from a pool);
  2. The first transaction finishes on this unblocked capability;
  3. MySQL then allows the second UPDATE to go through, and the second transaction finishes as well.
Issue 2: uninitialized thread-local state in libmysqlclient

To quote the docs:

When you call mysql_init(), MySQL creates a thread-specific variable for the thread that is used by the debug library (among other things). If you call a MySQL function before the thread has called mysql_init(), the thread does not have the necessary thread-specific variables in place and you are likely to end up with a core dump sooner or later.

Here’s the definition of the thread-local state data structure, taken from mariadb-10.0.17:

struct st_my_thread_var { int thr_errno; mysql_cond_t suspend; mysql_mutex_t mutex; mysql_mutex_t * volatile current_mutex; mysql_cond_t * volatile current_cond; pthread_t pthread_self; my_thread_id id; int volatile abort; my_bool init; struct st_my_thread_var *next,**prev; void *keycache_link; uint lock_type; /* used by conditional release the queue */ void *stack_ends_here; safe_mutex_t *mutex_in_use; #ifndef DBUG_OFF void *dbug; char name[THREAD_NAME_SIZE+1]; #endif };

This data structure is used by both server and client code, although it seems like most of these fields are used by the server, not client (with the exception of the dbug thing), which would explain why Haskellers have gotten away with not playing by the rules so far. However:

  1. I am not an expert, and I spent just about 20 minutes grepping the codebase. Am I sure that there’s no code path in the client that accesses this? No.
  2. Am I going to ignore the above warning and bet the stability of my production system on MySQL/MariaDB devs never making use of this thread-local state? Hell no!

What should we do to obey the rules?

First, make threads which work with MySQL bound, i.e. launch them with forkOS instead of forkIO. Otherwise, even if an OS thread is initialized, the Haskell thread may be later scheduled on a different, uninitialized OS thread.

If you create a connection in a thread, use it, and dispose of it, then using a bound thread should be enough. This is because mysql’s connect calls mysql_init, which in turn calls mysql_thread_init.

However, if you are using a thread pool or otherwise sharing a connection between threads, then connect may occur on a different OS thread than a subsequent use. Under this scenario, every thread needs to call mysql_thread_init prior to other MySQL calls.

Issue 3: non-thread-safe calls

The mysql_library_init function needs to be called prior to any other MySQL calls. It only needs to be called once per process, although it is harmless to call it more than once.

It is called implicitly by mysql_init (which is in turn called by connect). However, this function is documented as not thread-safe. If you connect from two threads simultaneously, bad or unexpected things can happen.

Also, if you are calling mysql_thread_init as described above, it should be called after mysql_library_init.

This is why it is a good idea to call mysql_library_init in the very beginning, before you spawn any threads.

Using a connection concurrently

This is not specific to the Haskell bindings, just something to be aware of:

You should not use the same MySQL connection simultaneously from different threads.

First, the docs explicitly warn you about that:

Multiple threads cannot send a query to the MySQL server at the same time on the same connection

(there are some details on this in case you are interested)

Second, the MySQL wire protocol is not designed to multiplex several communication «threads» onto the same TCP connection (unlike, say, AMQP), and trying to do so will probably confuse both the server and the client.


Here is, to the best of my knowledge, a correct example of concurrently accessing a MySQL database. The example accepts request at http://localhost/key and looks up that key in a MySQL table.

It needs to be compiled against my fork of mysql, which has the following changes compared to

  • Unsafe calls are marked as safe (the patch is due to Matthias Hörmann);
  • mysql_library_init and mysql_thread_init are exposed under the names initLibrary and initThread.

(How to use a fork that is not on hackage? For example, through a stackage snapshot.)

{-# LANGUAGE OverloadedStrings, RankNTypes #-} import Network.Wai import qualified Network.Wai.Handler.Warp as Warp import Network.HTTP.Types import qualified Database.MySQL.Base as MySQL import Database.MySQL.Simple import Control.Exception (bracket) import Control.Monad (void) import Control.Concurrent (forkOS) import qualified Data.Text.Lazy.Encoding as LT import Data.Pool (createPool, destroyAllResources, withResource) import Data.Monoid (mempty) import GHC.IO (unsafeUnmask) main = do MySQL.initLibrary bracket mkPool destroyAllResources $ \pool -> Warp.runSettings (Warp.setPort 8000 . Warp.setFork forkOSWithUnmask $ Warp.defaultSettings) $ \req resp -> do MySQL.initThread withResource pool $ \conn -> case pathInfo req of [key] -> do rs <- query conn "SELECT `desc` FROM `test` WHERE `key` = ?" (Only key) case rs of Only result : _ -> resp $ responseLBS ok200 [(hContentEncoding, "text/plain")] (LT.encodeUtf8 result) _ -> resp e404 _ -> resp e404 where mkPool = createPool (connect defaultConnectInfo) close 1 60 10 e404 = responseLBS notFound404 [] mempty forkOSWithUnmask :: ((forall a . IO a -> IO a) -> IO ()) -> IO () forkOSWithUnmask io = void $ forkOS (io unsafeUnmask)

The forkWithUnmask business is only an artifact of the way warp spawns threads; normally a simple forkOS would do. On the other hand, this example shows that in the real world you sometimes need to make an extra effort to have bound threads. Even warp got this feature only recently.

Note that this isn’t the most efficient implementation, since it essentially uses OS threads instead of lightweight Haskell threads to serve requests.

On destructors

The *_init functions allocate memory, so there are complementary functions, mysql_thread_end and mysql_library_end, which free that library.

However, you probably do not want to call them. Here’s why.

Most multithreaded Haskell programs have a small numbers of OS threads managed by the GHC runtime. These threads are also long-lived. Trying to free the resources associated with those threads won’t give much, and not doing so won’t do any harm.

Furthermore, suppose that you still want to free the resources. When should you do so?

Naively calling mysql_thread_end after serving a request would be wrong. It is only the lightweight Haskell thread that is finishing. The OS thread executing the Haskell thread may be executing other Haskell threads at the same time. If you suddenly destroy MySQL’s thread-local state, the effect on other Haskell threads would be the same as if you didn’t call mysql_thread_init in the first place.

And calling mysql_library_end without mysql_thread_end makes MySQL upset when it sees that not all threads have ended.

  1. GitHub issue bos/mysql#11: Address concurrency
  2. Leon P Smith: Concurrency And Foreign Functions In The Glasgow Haskell Compiler
  3. Edward Z. Yang: Safety first: FFI and threading
  4. Simon Marlow, Simon Peyton Jones, Wolfgang Thaller: Extending the Haskell Foreign Function Interface with Concurrency
  5. MySQL 5.6 Reference Manual: Writing C API Threaded Client Programs
Categories: Offsite Blogs

Haskell Jobs. 100% GHC Haskell. No Ruby, Scala, PHP, C++, or some Haskell like language.

Haskell on Reddit - Fri, 04/17/2015 - 1:05pm is hiring for two senior software engineer positions: a backend engineer and a site reliability engineer.

There is some overlap between the two positions, and the right candidate might find themself in-between the two positions, which is fine. is the leading enterprise scheduling service. We provide a white-label scheduling service that integrates seamlessly into our clients' businesses. Founded in 2009, is located in Manhattan, blocks away from central park.

Relocation is available, but remote is not.

Here are the links to the positions. Backend: Site Reliability:

If are interested please contact to setup an interview.

Jonathan Fischoff VP of Engineering at

submitted by jfischoff
[link] [31 comments]
Categories: Incoming News

Looking to build a web API for a single page app..

Haskell on Reddit - Fri, 04/17/2015 - 1:04pm

..and I'd like to use a library similar to Clojure's compojure. So far, scotty seems to be the one. Like I said, I'm basically just looking for a server library that allows me to start a server and define routes that will trigger functions that generate responses. Snap, Yesod, and Happstack all seem to handle this as well, but they also seem to carry around a lot of extra baggage. Reddit, what do you think about scotty in terms of being a lightweight way to define routes on a server? Would you suggest anything else? I'm used to the clojure ecosystem where the use of many small libraries is preferred over the use of large frameworks.

submitted by broma0
[link] [15 comments]
Categories: Incoming News

Proposal: liftData for Template Haskell

libraries list - Fri, 04/17/2015 - 12:21pm
I propose adding the following function to Language.Haskell.TH: -- | 'liftData' is a variant of 'lift' in the 'Lift' type class which -- works for any type with a 'Data' instance. liftData :: Data a => a -> Q Exp liftData = dataToExpQ (const Nothing) I don't really know which submodule this should come from; since it uses 'dataToExpQ', you might put it in Language.Haskell.TH.Quote but arguably 'dataToExpQ' doesn't belong in this module either, and it only lives there because it is a useful function for defining quasiquoters and it was described in the quasiquoting paper. I might propose getting rid of the 'Lift' class entirely, but you might prefer that class since it doesn't go through SYB (and have the attendant slowdown). This mode of use of 'dataToExpQ' deserves more attention. Discussion period: 1 month Cheers, Edward
Categories: Offsite Discussion

Strathclyde PhD Position

General haskell list - Fri, 04/17/2015 - 9:28am
Applications are welcome from ANYWHERE for a Microsoft Research sponsored PhD position in the Mathematically Structured Programming group at the University of Strathclyde. Project: Real World Data with Dependent Types: Integrity and Interoperation Strathclyde supervisor: Dr Conor McBride Microsoft supervisor: Dr Don Syme Starting: October 2015 Tuition fees: fully funded or substantially subsidised, depending on residency status Stipend: £14,057K Contact: Conor, by 8 May 2015 -------------------------------------------------------------------- Project Summary Data integrity, manipulation and analysis are key concerns in modern software, for developers and users alike. We are often obliged to work with a corpus of files – spreadsheets, databases, scripts – which represent and act on aspects of data in some domain. This project seeks to improve the integrity and effi
Categories: Incoming News

Deadline extended: WPTE 2015 Second International Workshop on Rewriting Techniques for Program Transformations and Evaluation

General haskell list - Fri, 04/17/2015 - 9:19am
FINAL CALL FOR PAPERS Second International Workshop on Rewriting Techniques for Program Transformations and Evaluation WPTE 2015 affiliated with RDP 2015 2 July, 2015, Warsaw, Poland !! Submission deadline is extended until April 24th !! Aims and Scope ============== The aim of WPTE is to bring together the researchers working on program transformations, evaluation, and operationally-based programming language semantics, using rewriting methods, in order to share the techniques and recent developments and to exchange ideas to encourage further activation of research in this area. The previous WPTE was held in Vienna 2014. Topics of interest in the scope of this workshop include: * Correctness of program transformations, optimizations and translations. * Program transformations for proving te
Categories: Incoming News