News aggregator

Brandon Simmons: Announcing: Hashabler 1.0. Now even more hashy with SipHash

Planet Haskell - Sun, 08/16/2015 - 8:15pm

I’ve just released version 1.0 of a haskell library for principled, cross-platform & extensible hashing of types. It is available on hackage, and can be installed with:

cabal install hashabler

(see my initial announcement post which has some motivation and pretty pictures)

You can see the CHANGELOG but the main change is an implementation of SipHash. It’s about as fast as our implementation of FNV-1a for bytestrings of length fifty and slightly faster when you get to length 1000 or so, so you should use it unless you’re wanting a hash with a simple implementation.

If you’re implementing a new hashing algorithm or hash-based data structure, please consider using hashabler instead of hashable.

Categories: Offsite Blogs

ANNOUNCE: broker-haskell v0.1

General haskell list - Sun, 08/16/2015 - 3:22pm
The initial release of broker-haskell, a Haskell binding to Broker (libbroker), the messaging library for Bro, a network security tool. Provides: - Language.Broker After downloading/extracting compressed tarball: davids-air-2:broker-haskell- dbanas$ cabal configure --prefix=$HOME --user --enable-tests Resolving dependencies... Configuring broker-haskell- davids-air-2:broker-haskell- dbanas$ cabal build Building broker-haskell- Preprocessing library broker-haskell- [1 of 1] Compiling Language.Broker ( dist/build/Language/Broker.hs, dist/build/Language/Broker.o ) {Some warnings omitted.} In-place registering broker-haskell- Preprocessing test suite 'tests' for broker-haskell- [1 of 1] Compiling Main ( test.hs, dist/build/tests/tests-tmp/Main.o ) {Some warnings omitted.} Linking dist/build/tests/tests ... davids-air-2:broker-haskell- dbanas$ cabal test Preprocessing library broker-haskell- In-place registering
Categories: Incoming News

Packages in haskell and licensing

haskell-cafe - Sun, 08/16/2015 - 1:09pm
Hey there, Is there currently any way to look up what licenses all your packages that you pull in have? For example, if I have a GPLv3 package, I want to make sure to not pull in any MIT dependencies. Is something like that currently possible or on the roadmap?
Categories: Offsite Discussion

Russell O'Connor: Bell’s Casino Problem

Planet Haskell - Sun, 08/16/2015 - 12:56pm

A new casino has opened up in town named “Bell’s Casino”. They are offering a coin game. The game works as follows.

The house will commit two coins on the table, oriented heads or tails each, and keep them covered. The player calls what the faces of the each of the coins are, either HH, HT, TH, or TT. The casino reveals the coins and if the player is correct, they win $1, and otherwise they lose $1.

Problem 1.
Prove that there is no strategy that can beat the casino.

After opening the customers stop coming by to play this boring game, so to boost attendance the casino modifies the game as follows.

The house will commit two coins on the table, oriented heads or tails each, and keep them covered. The player calls what the faces of each of the two coins are, either HH, HT, TH, or TT. The casino reveals one coin, of the players choice. After seeing revealed coin, the player can elect to back out of the game and neither win nor lose, or keep going, and see the second coin. If the player’s call is correct, they win $1, and otherwise they lose $1.

Problem 2.
Prove that there is no strategy that can beat the casino.

Even with the new, more fair, game, attendance at the casino starts dropping off again. The casino decides to offer a couples game.

The house will commit two coins on two tables, oriented heads or tails each, and keep them covered. The couple, together, calls what the the faces of each of the two coins are, either HH, HT, TH, or TT. Then, each player in the couple gets to see one coin each. Collectively they get to decide whether they are going to back out of the game or not by the following method. After seeing their revealed coin, each player will raise either a black flag or a red flag. If both players raise the different colour flags, the game ends and no one wins or loses. If both players raise the same colour flag, the game keeps going. If the couples original call was right, they win $1, and otherwise, they lose $1. To ensure that the couple cannot cheat, the two tables are places far enough apart such that each player’s decision on which flag to raise is space-like separated. Specifically the tables are placed 179 875 475 km apart and each player has 1 minute to decide which flag to raise otherwise a black flag will be raised on their behalf (or, more realistically, the tables are placed 400 m apart and each player has 100 nanoseconds to decide which flag to raise).

Problem 3.
Prove that there is no strategy for the couple that can beat the casino.
Problem 4.
Devise a physical procedure that a couple can follow to beat the casino on average at this last game without cheating.

The casino cannot figure out how they keep losing money on this game and, soon, Bell’s Casino goes bankrupt.

Categories: Offsite Blogs

Dimitri Sabadie: Never forget your git stashes again!

Planet Haskell - Sun, 08/16/2015 - 12:10pm

It’s been a while I’m experiencing issues with git stash. If you don’t know that command yet, git stash is used to move all the changes living in your staging area into a special place: the stash.

The stash is a temporary area working like a stack. You can push changes onto it via git stash or git stash save; you can pop changes from top with git stash pop. You can also apply a very specific part of the stack with git stash apply <stash id>. Finally you can get the list of all the stashes with git stash list.

We often use the git stash command to stash changes in order to make the working directory clear again so that we can apply a patch, pull some changes, change branch, and so on. For those purposes, the stash is pretty great.

However, I often forget about my stashes – I know I’m not the only one. Sometimes, I stash something and go to cook something or just go out, and when I’m back again, I might have forgotten about what I had stashed, especially if it was a very small change.

My current prompt for my shell, zsh, is in two parts. I set the PS1 environnment variable to set the regular prompt, and the RPROMPT environnment variable to set a reversed prompt, starting from the right of the terminal. My reversed prompt just performs a git command to check whether we’re actually in a git project, and get the current branch. Simple, but nice.

I came up to the realization that I could use the exact same idea to know whether I have stashed changes so that I never forget them! Here’s a screenshot to explain that:

As you can see, my prompt now shows me how many stashed changes there are around!

The code

I share the code I wrote with you. Feel free to use it, modify it and share it as well!

# …

function gitPrompt() {
# git current branch
currentBranch=`git rev-parse --abbrev-ref HEAD 2> /dev/null`
if (($? == 0))
echo -n "%F{green}$currentBranch%f"

# git stash
stashNb=`git stash list 2> /dev/null | wc -l`
if [ "$stashNb" != "0" ]
echo -n " %F{blue}($stashNb)%f"

echo ''

PS1="%F{red}%n%F{cyan}@%F{magenta}%M %F{cyan}%~ %F{yellow}%% %f"

# …

Have fun!

Categories: Offsite Blogs

Mark Jason Dominus: Math.SE report 2015-07

Planet Haskell - Sun, 08/16/2015 - 10:38am

My overall SE posting volume was down this month, and not only did I post relatively few interesting items, I've already written a whole article about the most interesting one. So this will be a short report.

  • I already wrote up Building a box from smaller boxes on the blog here. But maybe I have a couple of extra remarks. First, the other guy's proposed solution is awful. It's long and complicated, which is forgivable if it had answered the question, but it doesn't. And the key point is “blah blah blah therefore code a solver which visits all configurations of the search space”. Well heck, if this post had just been one sentence that ended with “code a solver which visits all configurations of the search space” I would not have any complaints about that.

    As an undergraduate I once gave a talk on this topic. One of my examples was the problem of packing 31 dominoes into a chessboard from which two squares have been deleted. There is a simple combinatorial argument why this is impossible if the two deleted squares are the same color, say if they are opposite corners: each domino must cover one square of each color. But if you don't take time to think about the combinatorial argument you could waste a lot of time on computer search learning that there is no solution in that case, and completely miss the deeper understanding that it brings you. So this has been on my mind for a long time.

  • I wrote a few posts this month where I thought I gave good hints. In How to scale an unit vector in such way that where is a scalar I think I did a good job identifying the original author's confusion; he was conflating his original unit vector and the scaled, leading him to write . This is sure to lead to confusion. So I led him to the point of writing and let him take it from there. The other proposed solution is much more rote and mechanical. (“Divide this by that…”)

    In Find numbers so that the OP got stuck partway through and I specifically addressed the stuckness; other people solved the problem from the beginning. I think that's the way to go, if the original proposal was never going to work, especially if you stop and say why it was never going to work, but this time OP's original suggestion was perfectly good and she just didn't know how to get to the next step. By the way, the notation here means the number .

    In Help finding the limit of this series it would have been really easy to say “use the formula” or to analyze the series de novo, but I think I almost hit the nail on the head here: it's just like , which I bet OP already knows, except a little different. But I pointed out the wrong difference: I observed that the first sequence is one-fourth the second one (which it is) but it would have been simpler to observe that it's just the second one without the . I had to review it just now to give the simpler explanation, but I sure wish I'd thought of it at the time. Nobody else pointed it out either. Best of all, would have been to mention both methods. If you can notice both of them you can solve the problem without the advance knowledge of the value of , because you have and then solve for .

    In Visualization of Rhombus made of Radii and Chords it seemed that OP just needed to see a diagram (“I really really don't see how two circles can form a rhombus?”), so I drew one.

Categories: Offsite Blogs

What are Haskellers' critiques of Scala?

Haskell on Reddit - Sun, 08/16/2015 - 9:19am

/u/klaxion kicked off a great discussion a few days ago regarding Haskellers' critiques of Clojure. To continue the theme: what are our critiques of Scala?

submitted by tew88
[link] [227 comments]
Categories: Incoming News

ANN: Amazonka 1.0

Haskell on Reddit - Sun, 08/16/2015 - 9:00am

A rather large number of updates to all of the Amazonka AWS SDKs have been released, including new features as well as some breaking changes. (Signified by the bump in major version.) In addition, there is now support for a total of 52 different AWS services.

Some formatted release notes are available here.

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

ghc-mod makes Emacs freeze on "Initializing..."

Haskell on Reddit - Sun, 08/16/2015 - 3:43am

Hello everyone,

3 down vote favorite I've been trying to learn Haskell the last couple of days so it was finally time to setup my environment. Thus, I installed Haskell Platform and cabal.

My editor is emacs and my OS is Windows.

I downloaded the ghc-mod's master branch from github and using cabal I installed the dependencies and then built the project. Everything went fine and the executable seems to work.

Commands like ghc-mod --version or ghc-mod boot work as expected.

Then, I installed haskell-mode on emacs and modified .emacs to use ghc. But when I tried to open a Haskell file, emacs froze saying "Initializing...".

What is the problem?

GHC version: 7.10.2 cabal version: using version of the cabal library ghc-mod version: compiled by GHC 7.10.2

Here are the lines I added to my .emacs:

; haskell-mode (add-hook 'haskell-mode-hook 'haskell-indentation-mode) ; ghc-mod for haskell ; I added to list path to ghc elisp file because I read somewhere that that's ; better than installing it from MELPA. I DID try to install it from melpa ; though. Didn't solve anything. (add-to-list `load-path "~/cabal/x86_64-windows-ghc-7.10.2/ghc-mod-") (autoload 'ghc-init "ghc" nil t) (autoload 'ghc-debug "ghc" nil t) (add-hook 'haskell-mode-hook (lambda () (ghc-init)))

Emacs freeze when I try to open a haskell file for the first time. So I guess it stacks in an infinite loop inside ghc-init().

submitted by The-Crafter
[link] [15 comments]
Categories: Incoming News

ACM Classic Books Series

Lambda the Ultimate - Sun, 08/16/2015 - 12:24am

This list of classic books is the result of a poll ACM conducted where members named their favorite computer science books.

Good list. Bar the last two, which I have nothing against, the list consists of favorites of mine. It is always nice to see how many classics of CS come from work on programming languages. Not a surprise for anyone here, of course, but not always acknowledged. While we are on the subject of classic books, check out Luke's twitter poll here.

Categories: Offsite Discussion

Ken T Takusagawa: [clomduww] Foldable with metadata

Planet Haskell - Sat, 08/15/2015 - 11:29pm

The Foldable instances of Array and Map in Haskell do not provide access to the index or key respectively. It is possible to provide such access, but doing so requires defining Foldable differently, making it a multiparameter type class and explicitly specifying an intermediate type that packages up the element and metadata, e.g., index or key.

GHC 7.10.1, array-, base-, containers-

{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, ScopedTypeVariables #-}
module FoldableWithKey where {
import Data.Array.IArray;
import qualified Data.Map as Map;

-- similar to Foldable, except the intermediate type can be different from the element type.
class FoldableWithKey collection intermediate where {
foldWithKey :: (intermediate -> b -> b) -> b -> collection -> b;

-- unclear why OVERLAPPABLE is needed here, as Map is clearly not an IArray
instance {-# OVERLAPPABLE #-} (IArray a e, Ix i) => FoldableWithKey (a i e) (i,e) where {
foldWithKey f z = foldr f z . assocs ;

instance FoldableWithKey (Map.Map k a) (k,a) where {
foldWithKey f = Map.foldWithKey $ \xk xa xb -> f (xk,xa) xb;

-- Overlapping Instance
-- Allows foldWithKey to be a drop-in replacement for foldr.
instance {-# OVERLAPPABLE #-} (Foldable t) => FoldableWithKey (t a) a where {
foldWithKey = foldr;

test1 :: [Int] -> Int;
test1 = foldWithKey (+) 0;

test2 :: Map.Map String Int -> Int;
test2 = foldWithKey (+) 0;

test3 :: Map.Map String Int -> (String,Int);
test3 = foldWithKey (\(s,i) (sold,iold) -> (s ++ sold, i + iold)) ("",0);

test4 :: Map.Map String Int -> Int;
-- explicit type signature weirdly needed on s
test4 = foldWithKey (\(s :: String, i) iold -> length s + i + iold) 0;

test5 :: Array Int Double -> Double;
-- explicit type signature weirdly needed on i
test5 = foldWithKey (\(i :: Int , d) dold -> d + dold + fromIntegral i) 0;

Categories: Offsite Blogs

libiconv trouble?

General haskell list - Sat, 08/15/2015 - 9:26pm
Anyone else hit this, after updating to the new Haskell Platform? Davids-MacBook-Air-2:tmp dbanas$ ghci GHCi, version 7.10.2: :? for help <command line>: can't load .so/.DLL for: libiconv.dylib (dlopen(libiconv.dylib, 5): image not found) Thanks, -db _______________________________________________ Haskell mailing list Haskell< at >
Categories: Incoming News

Redundant entries in .cabal file?

General haskell list - Sat, 08/15/2015 - 4:03pm
Hi all, Does anyone know why I’m getting redundant entries in my ‘cabal init’ generated .cabal file: library exposed-modules: Language.Broker, Language.Broker ? Is it because I’m using a *.hsc file, as my source, and cabal is finding both files: Broker.hsc, and Broker.hs in the Language directory? Thanks, -db _______________________________________________ Haskell mailing list Haskell< at >
Categories: Incoming News

Neil Mitchell: Testing is never enough

Planet Haskell - Sat, 08/15/2015 - 3:40pm

Summary: Testing shows the presence, not the absence of bugs.

Recently, someone suggested to me that, thanks to test suites, things like changing compiler version or versions of library dependencies was "no big deal". If dependency changes still result in a passing test suite, then they have caused no harm. I disagree, and fortunately for me, Dijkstra explains it far more eloquently than I ever could:

Testing shows the presence, not the absence of bugs. Dijkstra (1969)

While a test suite can give you confidence in changes you make, it does not provide guarantees. Below are just a few reasons why.

The test suite does not cover all the code

For any reasonably sized code base (> 100 lines), covering all the lines of code is difficult. There are a number of factors that mean that mean a test suite is unlikely to provide 100% coverage:

  • Producing tests is a resource intensive activity, and most projects do not have the necessary manpower to test everything.
  • Sometimes there is no good way to test simple sugar functions - the definition is a specification of what the function should do.
  • Testing corner cases is difficult. As the corners get more obscure, the difficulty increases.
  • Testing error conditions is even harder. Some errors conditions have code to deal with them, but are believed to be unreachable.

The test suite does not cover all the ways through the code

Assuming the test suite really does cover every line of the code, making it cover every path through the code is almost certainly computationally infeasible. Consider a program taking a handful of boolean options. While it might be feasible to test each individual option in the true and false states, testing every state in conjunction with every other state requires an exponential amount of time. For programs with loops, testing every number of loop iterations is likely to be highly time consuming.

There is plenty of code you can't see

Even if you cover every line of source code, the compiler may still thwart your valiant efforts. Optimising compilers like to inline code (make copies of it) and specialise code (freeze in some details that would otherwise be dynamic). After such transformations, the compiler might spot undefined behaviour (something almost all C/C++ programs contain) and make modifications that break your code. You might have tested all the source code, but you have not tested all the code generated by the compiler. If you are writing in C/C++, and undefined behaviour and optimisation doesn't scare you a lot, you should read this LLVM article series.

Functions have huge inputs

Testing functions typically involves supplying their input and inspecting their output. Usually the input space is too large to enumerate - which is likely to be the case even if your function takes in an integer. As soon as your function takes a string or array, enumeration is definitely infeasible. Often you can pick cases at which the code is likely to go wrong (0, 1, -1, maxBound) - but maybe it only fails for Carmichael numbers. Random testing can help, and is always advisable, but the effort to deploy random testing is typically quite a bit higher than input/output samples, and it is no panacea.

Functions are not functions

Testing functions usually assumes they really are functions, which depend only on their input. In pure functional languages that is mostly true, but in C/C++ it is less common. For example, functions that have an internal cache might behave differently under parallelism, especially if their cache is not managed properly. Functions may rely on global variables, so they might perform correctly until some seemingly unrelated operation is performed. Even Haskell programs are likely to depend on global state such as the FPU flags, which may be changed unexpectedly by other code.

In my experience, the non-functional nature of functions is one of the biggest practical difficulties, and is also a common place where dependency changes cause frustration. Buggy code can work successfully for years until an improved memory allocator allows a race condition to be hit.

Performance testing is hard

Even if your code gives the correct results, it may take too long or use too much memory. Alas, testing for resource usage is difficult. Resource numbers, especially runtime, are often highly variable between runs - more so if tests are run on shared hardware or make use of parallelism. Every dependency change is likely to have some impact on resource usage, perhaps as dependencies themselves chose to trade time for memory. Spotting erroneous variations often requires a human to make a judgement call.

What is the solution?

Tests help, and are valuable, and you should aim to test as much as you can. But for any reasonably sized program, your tests will never be complete, and the program will always contain unknown bugs. Most likely someone using your code will stumble across one of these bugs. In this case, it's often possible (and indeed, highly desirable) to add a new test case specifically designed to spot this error. Bugs have a habit of recurring, and a bug that happens twice is just embarrassing.

Thinking back to dependency versions, there is often strength in numbers. If all your users are on the same version of all the dependencies, then any bug that is very common is likely to be found by at least one user and fixed for all.

Thinking more generally, it is clear that many of these issues are somewhat ameliorated by pure functional programming. I consider testability and robustness to be one of the great strengths of Haskell.

Categories: Offsite Blogs

Redundant entries in .cabal file?

haskell-cafe - Sat, 08/15/2015 - 3:00pm
Hi all, Does anyone know why I’m getting redundant entries in my ‘cabal init’ generated .cabal file: library exposed-modules: Language.Broker, Language.Broker ? Is it because I’m using a *.hsc file, as my source, and cabal is finding both files: Broker.hsc, and Broker.hs in the Language directory? Thanks, -db _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >
Categories: Offsite Discussion