News aggregator

Proposal: Make default impls for foldl1 and foldr1 lazier

libraries list - Wed, 10/29/2014 - 8:08pm
We currently have (in Data.Foldable) foldr1 :: (a -> a -> a) -> t a -> a foldr1 f xs = fromMaybe (error "foldr1: empty structure") (foldr mf Nothing xs) where mf x Nothing = Just x mf x (Just y) = Just (f x y) and something similar for foldl1. This is strict in the entire spine, unlike the list version, because it has to get all the way to the end of the list before it starts laying down Justs. I propose we change this to the obvious: foldr1 :: (a -> a -> a) -> t a -> a foldr1 f xs = fromMaybe (error "foldr1: empty structure") (foldr mf Nothing xs) where mf x r = Just $ case r of Nothing -> x Just y -> f x y Since GHC 7.10.1 is fast approaching, I doubt we have the usual two weeks to discuss this, so please speak up as soon as you can if you have concerns. _______________________________________________ Libraries mailing list Libraries< at >haskell.org http://www.has
Categories: Offsite Discussion

Irreducible predicates error in Template Haskell

glasgow-user - Wed, 10/29/2014 - 4:27pm
Hello, we were trying to reify a typeclass, which had a ConstraintKind and we hit upon this error: "Can't represent irreducible predicates in Template Haskell:". It seems that there is already a ghc bug [ https://ghc.haskell.org/trac/ghc/ticket/7021 ] filed and its status is set as fixed, but there is a comment at the bottom in which the reviewer recommends against merging immediately. Does anybody know when it would get merged in?
Categories: Offsite Discussion

GHC Problem - new LLVM, "schedule: re-entered unsafely"

Haskell on Reddit - Wed, 10/29/2014 - 3:24pm

Hello! I'm at a loss as to how to solve my problem:

Compiling even a simple program

main = putStrLn "Hello World!"

I get a message

> ghc --make test > [1 of 1] Compiling Main ( test.hs, test.o ) > You are using a new version of LLVM that hasn't been tested yet! > We will try though... > Linking test...

Which might be the error; everything compiles fine (it seems), but it doesn't run properly.

> ./test > test: schedule: re-entered unsafely. > Perhaps a 'foreign import unsafe' should be 'safe'?

Last week I tried compiling a large cabal package, and decided to cancel since I have an ARM processor and it took too long. I don't seem to recall having this problem before this.

Any ideas? Should I try to rollback an earlier LLVM (I'm not familiar with LLVM at all) or might the cabal cancelling affect ghc in such a way?

Thank you!

also, sidenote: the packages I wanted were elm, elm-reactor and elm-server, I left cabal overnight running but ended up nowhere (hence cancel). Haven't found binaries for ARM or anything. Any ideas how I could get these packages?

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

Keegan McAllister: A taste of Rust (yum) for C/C++ programmers

Planet Haskell - Wed, 10/29/2014 - 1:15pm

If, like me, you've been frustrated with the status quo in systems languages, this article will give you a taste of why Rust is so exciting. In a tiny amount of code, it shows a lot of ways that Rust really kicks ass compared to C and C++. It's not just safe and fast, it's a lot more convenient.

Web browsers do string interningto condense the strings that make up the Web, such as tag and attribute names, into small values that can be compared quickly. I recently added event logging support to Servo's string interner. This will allow us to record traces from real websites, which we can use to guide further optimizations.

Here are the events we can log:


#[deriving(Show)]
pub enum Event {
Intern(u64),
Insert(u64, String),
Remove(u64),
}

Interned strings have a 64-bit ID, which is recorded in every event. The Stringwe store for "insert" events is like C++'s std::string; it points to a buffer in the heap, and it owns that buffer.

This enum is a bit fancier than a C enum, but its representation in memory is no more complex than a C struct. There's a tag for the three alternatives, a 64-bit ID, and a few fields that make up the String. When we pass or return an Event by value, it's at worst a memcpyof a few dozen bytes. There's no implicit heap allocation, garbage collection, or anything like that. We didn't define a way to copy an event; this means the String buffer always has a unique owner who is responsible for freeing it.

The deriving(Show) attribute tells the compiler to auto-generatea text representation, so we can print an Eventjust as easily as a built-in type.

Next we declare a global vector of events, protected by a mutex:


lazy_static! {
pub static ref LOG: Mutex<Vec<Event>>
= Mutex::new(Vec::with_capacity(50_000));
}

lazy_static! will initialize both of them when LOG is first used. Like String, the Vec is a growable buffer. We won't turn on event logging in release builds, so it's fine to pre-allocate space for 50,000 events. (You can put underscores anywhere in a integer literal to improve readability.)

lazy_static!, Mutex, and Vec are all implemented in Rust using gnarly low-level code. But the amazing thing is that all three expose a safe interface. It's simply not possible to use the variable before it's initialized, or to read the value the Mutex protects without locking it, or to modify the vector while iterating over it.

The worst you can do is deadlock. And Rust considers that pretty bad, still, which is why it discourages global state. But it's clearly what we need here. Rust takes a pragmatic approach to safety. You can always write the unsafe keywordand then use the same pointer tricks you'd use in C. But you don't need to be quite so guarded when writing the other 95% of your code. I want a language that assumes I'm brilliant but distracted :)

Rust catches these mistakes at compile time, and produces the same code you'd see with equivalent constructs in C++. For a more in-depth comparison, see Ruud van Asseldonk's excellent series of articlesabout porting a spectral path tracer from C++ to Rust. The Rust code performs basically the same as Clang / GCC / MSVC on the same platform. Not surprising, because Rust uses LLVMand benefits from the same backend optimizations as Clang.

lazy_static! is not a built-in language feature; it's a macro provided by a third-party library. Since the library uses Cargo, I can include it in my project by adding

[dependencies.lazy_static]
git = "https://github.com/Kimundi/lazy-static.rs"

to Cargo.toml and then adding


#[phase(plugin)]
extern crate lazy_static;

to src/lib.rs. Cargo will automatically fetch and build all dependencies. Code reuse becomes no harder than in your favorite scripting language.

Finally, we define a function that pushes a new event onto the vector:


pub fn log(e: Event) {
LOG.lock().push(e);
}

LOG.lock() produces an RAII handle that will automatically unlock the mutex when it falls out of scope. In C++ I always hesitate to use temporaries like this because if they're destroyed too soon, my program will segfault or worse. Rust has compile-time lifetime checking, so I can do things that would be reckless in C++.

If you scroll up you'll see a lot of prose and not a lot of code. That's because I got a huge amount of functionality for free. Here's the logging module again:


#[deriving(Show)]
pub enum Event {
Intern(u64),
Insert(u64, String),
Remove(u64),
}

lazy_static! {
pub static ref LOG: Mutex<Vec<Event>>
= Mutex::new(Vec::with_capacity(50_000));
}

pub fn log(e: Event) {
LOG.lock().push(e);
}

This goes in src/event.rsand we include it from src/lib.rs.


#[cfg(feature = "log-events")]
pub mod event;

The cfg attributeis how Rust does conditional compilation. Another project can specify

[dependencies.string_cache]
git = "https://github.com/servo/string-cache"
features = ["log-events"]

and add code to dump the log:


for e in string_cache::event::LOG.lock().iter() {
println!("{}", e);
}

Any project which doesn't opt in to log-eventswill see zero impact from any of this.

If you'd like to learn Rust, the Guide is a good place to start. We're getting close to 1.0and the important concepts have been stable for a while, but the details of syntax and libraries are still in flux. It's not too early to learn, but it might be too early to maintain a large library.

By the way, here are the events generated by interning the three strings foobarbaz foo blockquote:

Insert(0x7f1daa023090, foobarbaz)
Intern(0x7f1daa023090)
Intern(0x6f6f6631)
Intern(0xb00000002)

There are three different kinds of IDs, indicated by the least significant bits. The first is a pointer into a standard interning table, which is protected by a mutex. The other two are created without synchronization, which improves parallelism between parser threads.

In UTF-8, the string foois smaller than a 64-bit pointer, so we store the characters directly. blockquote is too big for that, but it corresponds to a well-known HTML tag. 0xb is the index of blockquote in a static listof strings that are common on the Web. Static atoms can also be used in pattern matching, and LLVM's optimizations for C's switch statements will apply.

Categories: Offsite Blogs

A bot question

Haskell on Reddit - Wed, 10/29/2014 - 10:41am

Hello guys,

Last week I saw a post about a website where people are competing with bots on a 4 man map free for all. You could kill other bots or gather resources, I want to say gold. But I can't for the life of me remember the name of the website. I want to believe it started with a V.

Reason that I post here is that I remember one bot being a Haskell bot. And I don't know where else to post this.

Sorry if this is vague but if you can help me that would be great

submitted by zerthz
[link] [2 comments]
Categories: Incoming News

Munich Haskell Meeting

haskell-cafe - Wed, 10/29/2014 - 9:49am
Dear all, tomorrow, the 30th of October, our monthly Munich Haskell Meeting will take place again at Cafe Puck at 19h30. For details see here: http://www.haskell-munich.de/dates If you plan to join, please click the button! Everybody is welcome! Heinrich
Categories: Offsite Discussion

lambda expressions. `\x -> exp` or `\ x -> exp`?

Haskell on Reddit - Wed, 10/29/2014 - 7:25am

Do you prefer a space between the \ and the first argument or not?

submitted by MrPopinjay
[link] [12 comments]
Categories: Incoming News

Thread behavior in 7.8.3

glasgow-user - Wed, 10/29/2014 - 7:18am
I have a general question about thread behavior in 7.8.3 vs 7.6.X I moved from 7.6 to 7.8 and my application behaves very differently. I have three threads, an application thread that plots data with wxhaskell or sends it over a network (depends on settings), a thread doing usb bulk writes, and a thread doing usb bulk reads. Data is moved around with TChan, and TVar is used for coordination. When the application was compiled with 7.6, my stream of usb traffic was smooth. With 7.8, there are lots of delays where nothing seems to be running. These delays are up to 40ms, whereas with 7.6 delays were a 1ms or so. When I add -N2 or -N4, the 7.8 program runs fine. But on 7.6 it runs fine without with -N2/4. The program is compiled -O2 with profiling. The -N2/4 version uses more memory, but in both cases with 7.8 and with 7.6 there is no space leak. I tired to compile and use -ls so I could take a look with threadscope, but the application hangs and writes no data to the file. The CPU fans run wild like it is
Categories: Offsite Discussion

Yesod Web Framework: Announcing: yesod-gitrepo

Planet Haskell - Wed, 10/29/2014 - 7:16am

I'm happy to announce the first release of a new package, yesod-gitrepo. This package encapsulates a pattern I've used a number of times, namely: loading and refreshing content from a Git repository. Below is the current contents of the README.md file.

This code is currently being used in production, and should be pretty stable. That said, it has not received a huge amount of battle testing yet. So please due test corner cases before shipping it in production for your site.

yesod-gitrepo provides a means of embedding content from a Git repository inside a Yesod application. The typical workflow is:

  • Use gitRepo to specify a repository and branch you want to work with.
  • Provide a function that will perform some processing on the cloned repository.
  • Use grContent in your Handler functions to access this parsed data.
  • Embed the GitRepo as a subsite that can be used to force a refresh of the data.
  • Set up a commit handler that pings that URL. On Github, this would be a webhook.

This is likely easiest to understand with a concrete example, so let's go meta: here's an application that will serve this very README.md file. We'll start off with language extensions and imports:

{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-} import ClassyPrelude.Yesod import Text.Markdown import Yesod.GitRepo

Now we're going to create our foundation datatype. We need to give it one field: the GitRepo value containing our parsed content. Our content will simply be the text inside README.md, wrapped up in a Markdown newtype for easy rendering. This gives us:

data App = App { getGitRepo :: GitRepo Markdown } instance Yesod App

And now let's set up our routes. We need just two: a homepage, and the subsite. Our subsite type is GitRepo Markdown (as given above). We replace the space with a hyphen as an escaping mechanism inside Yesod's route syntax:

mkYesod "App" [parseRoutes| / HomeR GET /refresh RefreshR GitRepo-Markdown getGitRepo |]

Next up is our home handler. We start off by getting the current content parsed from the repository:

getHomeR :: Handler Html getHomeR = do master <- getYesod content <- liftIO $ grContent $ getGitRepo master

Then it's just some normal Hamlet code:

defaultLayout $ do setTitle "yesod-gitrepo sample" [whamlet| <p> <a href=@{RefreshR GitRepoRoute}> Force a refresh at @{RefreshR GitRepoRoute} <article>#{content} |]

And finally, our main function. We pass in the repo URL and branch name, plus a function that, given the filepath containing the cloned repo, processes it and generates a Markdown value. Finally, we provide the generated repo value to our App constructor and run it:

main :: IO () main = do repo <- gitRepo "https://github.com/snoyberg/yesod-gitrepo" "master" $ \fp -> fmap Markdown $ readFile $ fp </> "README.md" warp 3000 $ App repo

Give it a shot. You should have a webapp hosting this very README file!

Categories: Offsite Blogs

Discussion: adding displayException to Exception class

libraries list - Wed, 10/29/2014 - 12:43am
I don't want to make a format proposal yet, just open up discussion on an issue, and see how others feel about it. As I recently commented on this list[1], the Show typeclass is overloaded with multiple meanings (serialization, debug info, and user-friendly data display). The general consensus seems to be that the official semantics for Show should be for serialization (as paired up with Read). However, there's at least one use case in base which explicitly uses Show for non-serialization purposes: the Exception class. All instances of Exception are required to have an instance of Show, but there's no way to actually serialize exceptions generally[2]. So by construction and by practice, the Show instance for Exception is used exclusively for the latter two categories I mentioned (debug info and user-friendly data display). As a result of that, it's quite common[3] to define a Show instance for exception types that is *not* serializable, but rather user friendly. This however seems to contradict what is ac
Categories: Offsite Discussion

Job announcement: formal methods engineer and scientificdeveloper at FireEye

General haskell list - Tue, 10/28/2014 - 4:19pm
Dear all, [My excuses if see this email more than once] the FireEye R&D center in Dresden, Germany, seeks outstanding formal-methods experts and scientific programmers to join FireEye's formal methods team in Dresden, Germany. Applicants should have a background in logical reasoning, (formal) software verification and functional programming. Please visit http://FireEye.com/careers for the concrete job descriptions. If you are interested or have questions, please contact me or Roland Carter <roland.carter< at >FireEye.com> or visit http://FireEye.com for more information about FireEye. FireEye is a next generation security company that provides the industry's leading threat protection technology. The formal methods team at FireEye works on the (formal) verification of a non-trivial piece of the software stack of one of FireEye's future products. Dresden is one the most beautiful cities in Germany with unique cultural attractions. The FireEye office is in the heart of the city, next to the famous historical cen
Categories: Incoming News

ANNOUNCE: Hasql: A minimalistic general high level API for relational databases

libraries list - Tue, 10/28/2014 - 4:02pm
This library takes a mission of upgrading the experience of dealing with relational databases in Haskell. It’s robust, it’s API is very concise, yet it’s packed with powerful features like the following: - An abstraction over transactions, which provides an automated resolution of conflicts. The API ensures that you’re only able to perform a specific set of actions in the transaction context, which allows Hasql to safely resolve conflicting transactions by automatically retrying them. This is much inspired by STM and ST. - Support for cursors. Allows to fetch virtually limitless result sets in a constant memory using streaming. - Employment of prepared statements. Every statement you emit gets prepared and cached. This raises the performance of the backend. - Automated management of resources related to connections, transactions and cursors. - A built-in connections pool. - Type-level generation of templates. You just can’t write
Categories: Offsite Discussion

Polymorphic case for this lens transformer?

haskell-cafe - Tue, 10/28/2014 - 3:40pm
Hi all, I have been using this lens transformer http://lpaste.net/113159. However, I can't seem to find a way to implement the polymorphic case (i.e. Lens instead of Lens'). What am I missing? Hans - Hans Höglund Composer, conductor and developer hans [at] hanshoglund.se hanshoglund.com https://twitter.com/hanshogl https://soundcloud.com/hanshoglund http://github.com/hanshoglund _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion