News aggregator

Philip Wadler: Codes that changed the world

Planet Haskell - Tue, 04/14/2015 - 7:04am
Aleks Krotoski tackles programming languages in BBC Radio 4's Codes that Changed the World. The five episodes comprise: Fortran, Cobol, Basic, Java, and The Tower of Babel. Functional programming and Haskell are singled out for special attention in the final programme, which includes a interview with Haskell developer Elise Huard; online is a clip of interview with Simon Peyton Jones that did not make it on air.


Categories: Offsite Blogs

FP Complete: Announcing: stackage-view

Planet Haskell - Tue, 04/14/2015 - 5:20am

As part of our announcement of open sourcing ide-backend, there was a video demonstrating a tool called “fpview” (that was our internal name for this tool).

<iframe allowfullscreen="allowfullscreen" frameborder="0" height="315" src="https://www.youtube.com/embed/FI3u8uqZ2Q4" width="420"></iframe>

Like many of our tools, after some internal development, we're now releasing it open source here at: stackage-view.

It looks like this:

The README documents the features, but here's a quick rundown:

  • Go to definition: You can double-click any identifier to jump straight to the definition.
  • Type information of any expression or pattern binding. Just click any identifier to see its type. Alternatively, you can select an expression to see the type of that. Hitting the <-> expansion button will expand the selection to a parent node.

The first purpose behind the tool was to target general teams of people who may not all be using the same tooling (Haskellers are like cats, they prefer to do their own thing!), some users may be on Emacs, Vim, or Sublime, FP Eclipse, Leksah, etc. whereas this read-only tool serves as a way to inspect a codebase with handy information and jumping available.

The second purpose was to serve as a demonstration and acid test for our combination GHCJS and React library ghcjs-react. It makes for a nice simple-but-non-trivial demonstration of the library. There is real-world state handling going on, interacting with third-party APIs (aside from React itself, the Ace editor).

It also serves as a demonstration of using ide-backend programmatically. If you look in the source of stackage-view you'll see it's quite straight-forward to use. To build it, you will need the Git version of ide-backend found here. Currently it cannot be uploaded to Hackage due to an issue with the -dynamic flag.

Categories: Offsite Blogs

New maintainer for wl-pprint

Haskell on Reddit - Tue, 04/14/2015 - 4:23am
Categories: Incoming News

Are these 2 statements equivalent?

Haskell on Reddit - Tue, 04/14/2015 - 3:22am

I was quizing myself and I got:

isUpp :: (Char b) => b -> Bool

but the answer is isUpperAlphanum :: Char -> Bool Are they equivalent?

submitted by tmtwd
[link] [10 comments]
Categories: Incoming News

Haskell Weekly News

haskell-cafe - Tue, 04/14/2015 - 3:02am
*Top picks:* - Aditya Siram announces the first release of Haskell bindings <http://haskell.1045720.n5.nabble.com/Announcement-FLTKHS-Bindings-to-the-FLTK-GUI-Toolkit-tp5768690.html> to the C++-based FLTK cross-platform GUI library. FLTK <http://www.fltk.org/> can be used to build a modern windows-and-widgets-based desktop app and comes with a UI builder called FLUID. - The startup called Helium releases a "homegrown Webmachine-inspired web framework in Haskell." <http://blog.helium.com/helium/2015/04/01/helium-webmachine-airship.html> Airship is very small (just under 1000 LoC) and extremely unopinionated: it works with any WAI-compatible web server and any templating language (including none at all!). Reddit discussion. <http://www.reddit.com/r/haskell/comments/312pk2/haskell_webmachine_airship/> - Adam Chlipala releases a new Ur/Web library for producing custom event-planning web apps <http://www.impredicative.com/pipermail/ur/2015-April/001928.html>
Categories: Offsite Discussion

Noam Lewis: The wl-pprint package maintainer…

Planet Haskell - Tue, 04/14/2015 - 1:52am

…is now me.

I’ve talked to the previous maintainer who is no longer interested. There was a small change required to support the new ghc (7.10), so I also released a new version. Since the new version only benefits people who need a new ghc, I also added the source-repository field in the cabal file, despite it breaking cabals older than 1.6.

According to hackage, wl-pprint was authored by Daan Leijen. The new github repo is up at https://github.com/sinelaw/wl-pprint.
I’ve taken the liberty of forking based on someone else’s patch for GHC 7.10 – thank you Alex Legg!

Incidentally, on hackage, there are several packages with the substring ‘wl-pprint’ in their names, some are newer and better maintained and have more features than others. This situation is rather confusing. wl-pprint itself is being used as a dependency by at least one package I need (language-ecmascript).

It would be nice if the community converged on a single Wadler-pretty-printer package. (Probably not wl-pprint – maybe ansi-wl-pprint?)


Categories: Offsite Blogs

Mads Lindstrøm: Producer Consumer example using GHCJS and NixOS

Planet Haskell - Tue, 04/14/2015 - 1:16am

For a time I have wanted to try GHCJS, but it was rumored to be hard to install. However, as I recently installed NixOS on my desktop computer and it has packages for GHCJS, I decided I would give GHCJS a shot. Bas van Diijk had made a mailing list post outlining how he uses uses GHCJS with NixOS. However, being new to NixOS and the Nix package manager language, I had a hard time understanding Bas van Diijk’s post. But with time and a lot of errors, I got a working setup. In this post I will describe what I did.

If you want to follow this howto, you properly already have NixOS installed. If not, you can find a good guide in the Nix Manual. If you want to install NixOS in a virtual machine this guide will help you.

Our example will depend on the unstable Nix package repository. Therefore do:

> mkdir ProducerConsumer > cd ProducerConsumer > git clone https://github.com/NixOS/nixpkgs.git

Unfortunately, I could not get the code to work with the newest version of Nix unstable. This is not necessarily surprising as unstable is a moving and not always perfectly working target – hence the name. But here the Nix way comes to the rescue, as one can just roll back the Nix Git repository back to when it did work:

> cd nixpkgs > git reset --hard 1901f3fe77d24c0eef00f73f73c176fae3bcb44e > cd ..

So with Nix you can easily follow the bleeding edge, without getting traped in a non-working unstable branch. I would not know how to do this easily with my former Linux distribution Debian.

We will start creating the client:

> mkdir client > mkdir client/src

We need a client/default.nix file descriping how to buld this client:

{ pkgs ? (import <nixpkgs> {}) , hp ? pkgs.haskellPackages_ghcjs # use ghcjs packages instead of ghc packages }: hp.cabal.mkDerivation (self: { pname = "ProducerConsumerClient"; version = "1.0.0"; src = ./.; isLibrary = false; isExecutable = true; buildDepends = [ hp.ghcjsDom hp.random hp.stm ]; buildTools = [ hp.cabalInstall ]; })

This is fairly standard default.nix for Haskell projects, except that we are using GHCJS instead of GHC. If you’re not familiar with Nix expressions, then a good guide can be found here.

We also need a Cabal file client/ProducerConsumerClient.cabal:

name: ProducerConsumerClient version: 1.0.0 author: Mads Lindstrøm build-type: Simple cabal-version: >=1.10 executable producer-consumer-client main-is: Main.hs build-depends: base >=4.7 && <4.8, ghcjs-dom >= 0.1.1.3, random >= 1.0.1.3, stm >= 2.4.2 hs-source-dirs: src default-language: Haskell2010

Finally we need to actually program. We create a small example with a producer and consumer of integers. And a showNumbersVar function, which presents the numbers to the user. We only have one source file client/src/Main.hs:

module Main ( main ) where import GHCJS.DOM import GHCJS.DOM.Document import GHCJS.DOM.HTMLElement import System.Random (randomRIO) import Control.Concurrent.STM (TVar, retry, atomically, modifyTVar, readTVar, newTVar) import Control.Concurrent (threadDelay, forkIO) main :: IO () main = do numbersVar <- atomically $ newTVar [1, 2, 3] forkIO (producer numbersVar) forkIO (consumer numbersVar) showNumbersVar [] numbersVar showNumbersVar :: [Int] -> TVar [Int] -> IO () showNumbersVar lastNumbers numbersVar = do currentNumbers <- atomically (do numbers <- readTVar numbersVar if lastNumbers == numbers then retry else return numbers ) Just doc <- currentDocument Just body <- documentGetBody doc htmlElementSetInnerHTML body ("<h1>" ++ unlines (map (\x -> show x ++ "<br>") currentNumbers) ++ "</h1>") showNumbersVar currentNumbers numbersVar producer :: TVar [Int] -> IO () producer numbersVar = do sleepMillies 500 2000 newNumber <- randomRIO (0, 100) atomically (modifyTVar numbersVar (newNumber:)) producer numbersVar consumer :: TVar [Int] -> IO () consumer numbersVar = do sleepMillies 500 2000 atomically (modifyTVar numbersVar (drop 1)) consumer numbersVar sleepMillies :: Int -> Int -> IO() sleepMillies minMs maxMs = randomRIO (minMs*1000, maxMs*1000) >>= threadDelay

This is ordinary Haskell and the code should not have many surprises for the experienced Haskell programmer. It is very nice that we can use Software Transactional Memory (STM) to handle integer list. STM is likely to be especially helpful in a user interface application, where there necessarily is a lot of concurrency.

We can build the client now:

> nix-build -I . client

If successful you should get a link called result, which points to the ProducerConsumerClient in the Nix store. Try:

> ls -l result/bin/producer-consumer-client.jsexe/

Where you should see some files including javascript and html files.

Next the server part. The server parts needs access to the client. We can achieve this by creating a Nix expression pointing to both client and server. Create packages.nix:

{ pkgs ? import <nixpkgs> {} }: rec { client = import ./client { }; server = import ./server { inherit client; }; }

The server will be a simple Snap application, which just serves the JavaScript files created by ProducerConsumerClient.

We need a server directory:

> mkdir server > mkdir server/src

And server/default.nix:

{ pkgs ? (import <nixpkgs> {}) , hp ? pkgs.haskellPackages_ghc784 , client }: hp.cabal.mkDerivation (self: { pname = "ProducerConsumerServer"; version = "1.0.0"; src = ./.; enableSplitObjs = false; buildTools = [ hp.cabalInstall ]; isExecutable = true; isLibrary = false; buildDepends = [ hp.MonadCatchIOTransformers hp.mtl hp.snapCore hp.snapServer hp.split hp.systemFilepath client ]; extraLibs = [ ]; preConfigure = '' rm -rf dist ''; postInstall = '' # This is properly not completely kosher, but it works. cp -r $client/bin/producer-consumer-client.jsexe $out/javascript ''; inherit client; })

And server/ProducerConsumerServer.cabal:

Name: ProducerConsumerServer Version: 1.0 Author: Author Category: Web Build-type: Simple Cabal-version: >=1.2 Executable producer-consumer-server hs-source-dirs: src main-is: Main.hs Build-depends: base >= 4 && < 5, bytestring >= 0.9.1 && < 0.11, MonadCatchIO-transformers >= 0.2.1 && < 0.4, mtl >= 2 && < 3, snap-core >= 0.9 && < 0.10, snap-server >= 0.9 && < 0.10, split >= 0.2.2, system-filepath >= 0.4.13, filepath >= 1.3.0.2 ghc-options: -threaded -Wall -fwarn-tabs -funbox-strict-fields -O2 -fno-warn-unused-do-bind

And server/src/Main.hs:

{-# LANGUAGE OverloadedStrings #-} module Main where import Prelude hiding (head, id, div) import qualified Prelude import Snap.Core (Snap, dir, modifyResponse, addHeader) import Snap.Util.FileServe (serveDirectory) import Snap.Http.Server (quickHttpServe) import System.Environment (getEnvironment, getEnv, getExecutablePath) import System.FilePath import Data.List.Split (splitOn) import Data.List (isInfixOf) main :: IO () main = do exePath <- getExecutablePath let baseDir = takeDirectory exePath ++ "/../javascript/" quickHttpServe $ site baseDir getClientDir :: IO String getClientDir = do getEnvironment >>= mapM_ print nativeBuildInputs <- getEnv "propagatedNativeBuildInputs" return $ Prelude.head $ filter (isInfixOf "my-test-app") $ splitOn " " nativeBuildInputs site :: String -> Snap () site clientDir = do Snap.Core.dir "client" (serveDirectory clientDir) let header key value = modifyResponse (addHeader key value) header "Cache-Control" "no-cache, no-store, must-revalidate" header "Pragma" "no-cache" header "Expires" "0"

Now we can compile the client, using packages.nix, and the server:

> nix-build -I . packages.nix -A client > nix-build -I . packages.nix -A server

Now it is time to run the application:

> result/bin/producer-consumer-server

and point your browser to http://localhost:8000/client. You should see the numbers one, two, and three. After about a second you should see the numbers lists changing, as the producer and consumer changes the list.


Categories: Offsite Blogs

ANNOUNCE: fast-tags 1.0

haskell-cafe - Mon, 04/13/2015 - 10:53pm
fast-tags makes vi (and now emacs) tags from haskell source. It does so quickly and incrementally. I have it bound to vim's BufWrite to keep tags always updated, and it's basically instant. It works with hsc, literate haskell, and mid-edit files with syntax errors. I've announced this before, but I'm doing it again because it's been a long time and there was a major update. I bumped to 1.0 to reflect that it's not dead, it just does everything I need it to do, so further development is unlikely unless someone finds a bug. That's just for me of course, if someone else wants to add features they are welcome to do so. The major update was almost entirely thanks to Sergey Vinokurov and a few others who contributed a bunch of patches. Details and changelog are at http://hackage.haskell.org/package/fast-tags-1.0 Source is at https://github.com/elaforge/fast-tags
Categories: Offsite Discussion

How to approach implementing imperative algorithms functionally?

Haskell on Reddit - Mon, 04/13/2015 - 8:49pm

Recently, I experimented with implementing Eugene Myers' "diff algorithm". The same algorithm that the well known UNIX diff program is based on.

Working through the paper, I got to a part where pseudo-code was presented that was very imperative in nature. It relied on nested loops, calculating based on an array that was written and rewritten repeatedly and using values based on array indices and associated values. It was not obvious to me how to translate this into a functional implementation.

In general, is translating imperative algorithms to functional implementations supposed to be straightforward or non-straightforward? Are there rules of thumb to follow or must each algorithm's functional expression be worked out individually?

And specifically for the pseudo-code linked above, what would be a good way to structure the code to implement it?

submitted by stasiana
[link] [53 comments]
Categories: Incoming News

LOLA 2015: Second Call for Talk Proposals

General haskell list - Mon, 04/13/2015 - 5:29pm
SECOND CALL FOR TALK PROPOSALS ______________________________________________________________________ LOLA 2015: Syntax and Semantics of Low Level Languages Sunday, 5 July 2015, Kyoto, Japan A satellite workshop of ICALP/LICS http://lola15.tcs.ifi.lmu.de ______________________________________________________________________ /Important Dates/ Abstract submission: Monday, 20 April 2015 Author notification: Friday, 1 May 2015 LOLA 2015 workshop: Sunday, 5 July 2015 /Invited Speakers/ Katsuhiro Ueno, Tohoku University, Japan Other invited speakers to be announced. /Workshop Description/ It has been understood since the late 1960s that tools and structures arising in mathematical logic and proof theory can usefully be applied to the design of high level programming languages, and to the development of reasoning principles for such languages. Yet low level languages, such as machine code, and the compilation of high level languages into a low level ones have traditionally been seen as having little
Categories: Incoming News

Why no Floating instance for Data.Fixed /Data.Fixed.Binary

haskell-cafe - Mon, 04/13/2015 - 4:31pm
I'm wondering why the decision was made not to have a Floating instance for Data.Fixed. I understand that -- being a fixed point number type -- it doesn't line up with the name of the Floating typeclass. But it also seems that Floating is misnamed, because none of the functions there really have anything to do with floating point representation. This is why we still have Floating instances for, say, exact reals or symbolic numbers, neither of which has a floating point representation. It seems that the actual criterion for membership in Floating is something like "has a canonical choice for degree of approximation". Double and Float are in because we round to the nearest value. Exact reals are in because we don't have to approximate, symbolic numbers too. Rational is out because there's no clear choice of how to approximate. But by this criterion, Data.Fixed should be in. And indeed it would be useful for it to be in. If I choose to represent values from the real world by a fixed point approximation inst
Categories: Offsite Discussion

Improvements to package hosting and security

haskell-cafe - Mon, 04/13/2015 - 11:02am
Many of you saw the blog post Mathieu wrote[1] about having more composable community infrastructure, which in particular focused on improvements to Hackage. I've been discussing some of these ideas with both Mathieu and others in the community working on some similar thoughts. I've also separately spent some time speaking with Chris about package signing[2]. Through those discussions, it's become apparent to me that there are in fact two core pieces of functionality we're relying on Hackage for today: * A centralized location for accessing package metadata (i.e., the cabal files) and the package contents themselves (i.e., the sdist tarballs) * A central authority for deciding who is allowed to make releases of packages, and make revisions to cabal files In my opinion, fixing the first problem is in fact very straightforward to do today using existing tools. FP Complete already hosts a full Hackage mirror[3] backed by S3, for instance, and having the metadata mirrored to a Git repository as well is not a d
Categories: Offsite Discussion

Static executables in minimal Docker containers

haskell-cafe - Mon, 04/13/2015 - 9:54am
I'm trying to put together a minimal Docker container consisting of nothing but GHC-compiled static executables. Below you can see a full interaction I've had with GHC and Docker. The high level summary is that: * When compiled statically, the executable runs just fine in both my host OS (Ubuntu 14.04) and an Ubuntu 14.04 Docker image * That same executable run from a busybox (or a "scratch" image, not shown here since it's slightly longer to set up) hangs and then runs out of memory I've watched the process in top, and it uses up a huge amount of CPU and memory. I get the same behavior whether I compiled with or without optimizations or the multithreaded runtime. I also get identical behavior with both GHC 7.8.4 and 7.10.1. I'm not sure how best to proceed with trying to debug this, any suggestions? vagrant< at >vagrant-ubuntu-trusty-64:~/Desktop$ cat > hello.hs <<EOF main :: IO () main = putStrLn "Static Hello" EOF vagrant< at >vagrant-ubuntu-trusty-64:~/Desktop$ ghc -optl-static -optl-pthread hello.hs -static [
Categories: Offsite Discussion

If n-tuples were just nested pairs

Haskell on Reddit - Mon, 04/13/2015 - 8:47am

I've been mulling over this thought for a while. I know that Haskell is not like this, but it seems like it would have been a design improvement, and I've never seen it explicitly mentioned before. What if n-tuples (triples, quadruples, etc.) where just syntactic sugar for nested tuples? Roughly speaking:

type (a,b,c) = (a,(b,c)) -- or maybe even ((a,b),c) type (a,b,c,d) = (a,(b,(c,d))) -- etc.

You could make it associate in the other direction instead if you wanted and then you would get the formulation in my comment. That is not a super important point here. Nesting works out better for typeclasses and currying (particularly for multiple arguments, as in uncurry . uncurry . uncurry), and you could still get the aesthetic benefit of not having so many parentheses. Anyway, if anyone else has thought about this or has any thoughts on downsides to this, I would enjoying hearing from you.

submitted by andrewthad
[link] [40 comments]
Categories: Incoming News