News aggregator

Binary Sum

Haskell on Reddit - Wed, 06/24/2015 - 9:34am

i need tips to make a sum with two binary numbers, the right way to do it, i guess its coverting to two complements binary.

submitted by chocsx
[link] [4 comments]
Categories: Incoming News

Generalizing a library

haskell-cafe - Wed, 06/24/2015 - 9:30am
Hi Cafe! I've written very first version of GHCJS port <https://github.com/geraldus/ghcjs-perch> of Perch <https://github.com/agocorona/haste-perch> library originally designed to work with Haste compiler. Most of work is already done, though some polishing is needed. In essence Haste and GHCJS versions are very similar, the major difference is how foreign functions are defined, and in fact Perch is built using just a few low-level primitives <https://github.com/geraldus/ghcjs-perch/blob/master/src/Internal/FFI.hs>. So, as these libraries are very similar I want to generalize Perch to make it independent of compiler somehow. My initial idea was to have a Perch library and several compiler specific back-ends which user should select depending on his toolchain, but my Haskell skills are still very poor to find a proper way to do this. Can someone point me in right direction or at least give some advices? Very appreciate any help! _______________________________________________ Haskell-Cafe mailing list
Categories: Offsite Discussion

FP Complete: Why is stack not cabal?

Planet Haskell - Wed, 06/24/2015 - 7:00am

This blog post is intended to answer two very frequest questions about stack: how is it different from Cabal? And: Why was it developed as a separate project instead of being worked on with Cabal?

Before we delve into the details, let’s first deconstruct the premises of the questions. There are really three things that people talk about when they say “Cabal”:

  1. a package metadata format (.cabal files) and specification for a “common architecture for building applications and tools”, aka Cabal-the-spec,
  2. an implementation of the spec as a framework, aka Cabal-the-library,
  3. cabal-install, aka Cabal-the-tool, which is a command-line tool that uses Cabal-the-library.

Stack complies with Cabal-the-spec, both in the sense that it groks .cabal files in their entirety and behaves in a way that complies with the spec (insofar as that is relevant since the spec hasn’t seen any updates in recent years). In fact it was easy for Stack to do, because just like Cabal-the-tool, it is implemented using Cabal-the-library. Therefore, a first answer to the questions at hand is that stack is Cabal: it is 100% compatible with the existing Cabal file format for specifying package metadata, supports exactly the same package build harnesses and is implemented on top of the same reference implementation of the spec as cabal-install, which is just one tool among others using Cabal-the-library. cabal-install and stack are separate tools that both share the same framework. A successful framework at that: Haskell’s ecosystem would not be where it is today without Cabal, which way back in 2004, for the first time in the long history of Haskell made it possible to easily reuse code across projects by standardizing the way packages are built and used by the compiler.

Stack is different in that it is a from-the-ground-up rethink of Cabal-the-tool. So the real questions are: why was a new tool necessary, and why now? We’ll tackle these questions step-by-step in the remainder of this post:

  • What problem does stack address?
  • How are stack’s design choices different?
  • stack within the wider ecosystem
The problem

Stack was started because the Haskell ecosystem has a tooling problem. Like any number of other factors, this tooling problem is limiting the growth of the ecosystem and of the community around it. Fixing this tooling problem was born out of a systematic effort of growth hacking: identify the bottlenecks that hamper growth and remove them one by one.

The fact that Haskell has a tooling problem is not a rumour, nor is it a fringe belief of disgruntled developers. In an effort to collect the data necessary to identifying the bottlenecks in the growth of the community, FP Complete conducted a wide survey of the entire community on behalf of the Commercial Haskell SIG. The results are in and the 1,200+ respondents are unequivocal: package management with cabal-install is the single worst aspect of using Haskell. Week after week, Reddit and mailing list posts pop up regarding basic package installation problems using cabal-install. Clearly there is a problem, no matter whether seasoned users understand their tools well, know how to use it exactly right and how to back out gracefully from tricky situations. For every battle hardened power user, there are 10 enthusiasts willing to give the language a try, if only simple things were simple.

Of a package building and management tool, users expect, out-of-the-box (that means, by default!):

  1. that the tool facilitates combining sets of packages to build new applications, not fail without pointing to the solution, just because packages advertize conservative bounds on their dependencies;
  2. that the tool ensures that success today is success tomorrow: instructions that worked for a tutorial writer should continue to work for all her/his readers, now and in the future;
  3. that invoking the tool to install one package doesn’t compromise the success of invoking the tool for installing another package;
  4. that much like make, the UI not require the user to remember what previous commands (s)he did or did not run (dependent actions should be run automatically and predictably).

In fact these are the very same desirable properties that Johan Tibell identified in 2012 and which the data supports today. If our tooling does not support them, this is a problem.

Stack is an attempt to fix this problem - oddly enough, by building in at its core much of the same principles that underlie how power users utilize cabal-install successfully. The key to stack’s success is to start from common workflows, choosing the right defaults to support them, and making those defaults simple.

The design

One of the fundamental problems that users have with package management systems is that building and installing a package today might not work tomorrow. Building and installing on my system might not work on your system. Despite typing exactly the same commands. Despite using the exact same package metadata. Despite using the exact same version of the source code. The fundamental problem is: lack of reproducibility. Stack strives hard to make the results of every single command reproducible, because that is the right default. Said another way, stack applies to package management the same old recipe that made the success of functional programming: manage complexity by making the output of all actions proper functions of their inputs. State explicitly what your inputs are. Gain the confidence that the outputs that you see today are the outputs that you see tomorrow. Reproducibility is the key to understandability.

In the cabal workflow, running cabal install is necessary to get your dependencies. It's also a black box which depends on three pieces of global, mutable, implicit state: the compiler and versions of system libraries on your system, the Cabal packages installed in GHC’s package database, and the package metadata du jour downloaded from Hackage (via cabal update). Running cabal install at different times can lead to wildly different install plans, without giving any good reason to the user. The interaction with the installed package set is non-obvious, and arbitrary decisions made by the dependency solver can lead to broken package databases. Due to lack of isolation between different invocations of cabal install for different projects, calling cabal install the first time can affect whether cabal install will work the second time. For this reason, power users use the cabal freeze feature to pin down exactly the version of every dependency, so that every invocation of cabal install always comes up with the same build plan. Power users also build in so-called “sandboxes”, in order to isolate the actions of calling cabal install for building the one project from the actions of calling cabal install for building this other project.

In stack, all versions of all dependencies are explicit and determined completely in a stack.yaml file. Given the same stack.yaml and OS, stack build should always run the exact same build plan. This does wonders for avoiding accidentally breaking the package database, having reproducible behavior across your team, and producing reliable and trustworthy build artifacts. It also makes it trivial for stack to have a user-friendly UI of just installing dependencies when necessary, since future invocations don’t have to guess what the build plan of previous invocations was. The build plan is always obvious and manifest. Unlike cabal sandboxes, isolation in stack is complete: packages built against different versions of dependencies never interfere, because stack transparently installs packages in separate databases (but is smart enough to reuse databases when it is always safe to do, hence keeping build times low).

Note that this doesn’t mean users have to painstakingly write out all package versions longhand. Stack supports naming package snapshots as shorthand for specifying sets of package versions that are known to work well together.

Other key design principles are portability (work consistently and have a consistent UI across all platforms), and very short ramp-up phase. It should be easy for a new user with little knowledge of Haskell to write “hello world” in Haskell, package it up and publish it with just a few lines of configuration or none at all. Learning a new programming language is challenge enough that learning a new package specification language is quite unnecessary. These principles are in contrast with those of platform specific and extremely general solutions such a Nix.

Modularity (do one thing and do it well), security (don’t trust stuff pulled from Internet unless you have a reason to) and UI consistency are also principles fundamental to the design, and a key strategies to keeping the bug count low. But more on that another time.

These have informed the following "nice to have" features compared to cabal-install:

  • multi-package project support (build all packages in one go, test all packages in one go…),
  • depend on experimental and unpublished packages directly, stored in Git repositories, not just Hackage and the local filesystem,
  • transparently install the correct version of GHC automatically so that you don’t have to (and multiple concurrently installed GHC versions work just fine),
  • optionally use Docker for bullet-proof isolation of all system resources and deploying full, self-contained Haskell components as microservices.

The technologies underpinning these features include:

  • Git (for package index management),
  • S3 (for high-reliability package serving),
  • SSL libraries (for secure HTTP uploads and downloads),
  • Docker,
  • many state-of-the-art Haskell libraries.

These technologies have enabled swift development of stack without reinventing the wheel and have helped keep the implementation stack simple and accessible. With the benefit of a clean slate to start from, we believe stack to be very hackable and easy to contribute to. These are also technologies that cabal-install did not have the benefit of being able to use when it was first conceived some years ago.

Whither cabal-install, stack and other tools

Stack is but one tool for managing packages on your system and building projects. Stack was designed specifically to interoperate with the existing frameworks for package management and package building, so that all your existing packages work as-is with stack, but with the added benefit of a modern, predictable design. Because stack is just Cabal under the hood, other tools such as Halcyon for deployment and Nix are good fits complement stack nicely, or indeed cabal-install for those who prefer to work with a UI that they know well. We have already heard reports of users combining these tools to good effect. And remember: stack packages are cabal-install packages are super-new-fangled-cabal-tool packages. You can write the exact same packages in stack or in another tool, using curated package sets if you like, tight version bounds à la PVP if you like, none or anything at all. stack likes to make common usage easy but is otherwise very much policy agnostic.

Stack is a contributor friendly project, with already 18 contributors to the code in its very short existence, several times more bug reporters and documentation writers, and counting! Help make stack a better tool that suits your needs by filing bug reports and feature requests, improving the documentation and contributing new code. Above all, use stack, tell your friends about it. We hope stack will eliminate a documented bottleneck to community growth. And turn Haskell into a more productive language accessible to many more users.

Categories: Offsite Blogs

Cabal cannot resolve dependencies for my Yesod website

libraries list - Wed, 06/24/2015 - 5:07am
Hello, all, I am trying to make the next big thing with Yesod -- but for now, just a Hello World website. After getting it running locally, I tried to integrate it with Circle CI, which has support for cabal-based Haskell projects. Circle CI runs the following commands: cabal sandbox init cabal install --upgrade-dependencies --constraint="template-haskell installed" --dependencies-only --enable-tests With this invocation, cabal cannot resolve dependencies no matter how I change the cabal config. If, however, I run just `cabal install`, everything works. This cabal failure occurs both on a CircleCI host and my laptop exactly the same way, so I know it's not my environment. I wrote a StackOverflow question with more details: http://stackoverflow.com/questions/31010999/cabal-cannot-resolve-dependencies-chooses-wrong-version-of-containers The github repo, for ease of reproducing the problem: https://github.com/philipmw/yesod-website I hope that someone on the list is able to help. Thanks.
Categories: Offsite Discussion

Jade for Haskell

Haskell on Reddit - Wed, 06/24/2015 - 1:36am

Does anyone know of a Jade interpreter in Haskell?

I have a server for my site written in go that uses Amber templates (Amber is go's version of Jade, which is from nodeJS and a port to PHP). Since the site is full of files of that format, I want to create a Haskell server that will serve them just like the go server does. Trying to see if one is better than the other.

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

ANNOUNCE: stack 0.1.0.0

haskell-cafe - Tue, 06/23/2015 - 6:24pm
Announcing stack, a new build tool, first stable release. More information at: https://www.fpcomplete.com/blog/2015/06/stack-0-1-release
Categories: Offsite Discussion

Bibliographic references on advantages of functionallanguages for refactoring

haskell-cafe - Tue, 06/23/2015 - 5:11pm
Hi all, I’m writing my master thesis, which is not itself about functional programming but I use Haskell as the language chosen for the implementation of whatever I’m talking about. To motivate the choice more than “I like the language” I’m arguing that since I’m implementing experimental stuff and I’ll need to change the code and refactor very often, a strongly typed language is what I need. I wrote this sentence: "Strongly-typed programming eases the refactoring process by leveraging the compiler to spot wrong transformations before they turn into runtime bugs” Since this thesis is not itself about functional programming this sentence needs to be backed by something. In other words I need to cite some published paper where this is said/surveyed/proved/whatever. So the question: can you help me find referentiable published work relative to how strongly-typed functional programming eases refactoring? A survey or some case-study report or some functional pearl, dunno. Thank you very mu
Categories: Offsite Discussion

Noam Lewis: In Python, don’t initialize local variables unnecessarily

Planet Haskell - Tue, 06/23/2015 - 12:07pm

A common pattern:

def foo(): x = some value # but do we need this? (short answer: no) if something: # ... do stuff ... x = 'bla' else: x = 'blo'

The variable x is being initialized before the if/else, but the intention of the programmer is that its value will actually be determined by the if/else itself. If somebody later comes around and mistakenly removes one of the assignments (inside ‘if’ or ‘else’), no runtime error will occur and x will remain initialized to a probably wrong value.

Leaving out the initialization is better – in that case, forgetting to set x in one of the branches will cause an UnboundLocalError:

>>> def foo(): ... if False: ... x = 0 ... return x ... >>> foo() Traceback (most recent call last): File "", line 1, in File "", line 4, in foo UnboundLocalError: local variable 'x' referenced before assignment

Errors are good! (when they flag buggy code)

Now, what if we also have an x declared in the global scope? Because of how Python handles variable scope, the error will still happen (which is good).

>>> x = 1 >>> def foo(): ... if False: ... x = 0 ... return x ... >>> foo() Traceback (most recent call last): .. UnboundLocalError: local variable 'x' referenced before assignment

Summary: In Python, don’t initialize variables until you know what value to assign to them.


Categories: Offsite Blogs

Ghc 7.10.1 Alpine packages

Haskell on Reddit - Tue, 06/23/2015 - 11:22am

Ok so I figure I might as well release this to the world. It works decently enough for my purposes the past week or so.

So voila, ghc 7.10.1 alpine packages. I'm pestering the Alpine developers to get this into the testing repository proper but in the interim, have fun. Note this is compiled with -O2, when you recompile ghc a lot binary size starts to seem a minor problem.

https://github.com/mitchty/alpine-linux-ghc-bootstrap/tree/master

The readme should cover things I found/know about. The examples directory has everything you'd need to use these packages in a Dockerfile. The stage1/2/3 directories have a mostly working setup on how I got to native packages within alpine linux.

Consider it alpha grade though. I can compile things like idris with it and they work. But I haven't validated its correct. Only that things compile and don't segfault straight away.

Also not entirely sure if having a ghc/ghc-dev package split makes sense to be honest.

Next up on my list is automating rebuilds for cabal-install and ghc itself so that when 7.10.2/next cabal version is out I'm set to update this jazz.

Also many thanks to everyone in #ghc that helped me with this as well as anyone I may be missing/forgetting about. Have to go help debug a problem.

Enjoy!

submitted by saudade
[link] [5 comments]
Categories: Incoming News

FP Complete: stack 0.1 released

Planet Haskell - Tue, 06/23/2015 - 11:00am

A few weeks ago, we announced the first public beta of stack, a new build tool for Haskell. Since then we've seen a huge amount of work on stack: code contributions, feature requests, bug reports, and design discussions. In other words, the response we've had from the community has been amazing. Thank you for helping us push forward with improved Haskell tooling.

Today we're announcing a new milestone: we believe that stack is now stable enough to be the standard build tool for most Haskell development. We're taking the beta label off of stack, and recommending people dive in. Please keep in mind that stack is still young software, and there are likely corner cases that haven't been worked out fully. However, the feedback we've received from other users has indicated that stack is ready. The stack team itself (both inside and outside of FP Complete) has been using stack for months now as its primary tool. And at FP Complete, we've already moved our biggest projects over to it.

Relevant links:

One question which I've personally held off on addressing until now is a direct comparison between stack and other build tools, cabal being the most obvious comparison. Expect a blog post on the subject in the near future. For now, my recommendation is: try out stack, and see if you like it.

Bringing Haskell to the masses

While stack started with the needs of existing Commercial Haskell users, the goal we've always had in mind for it is a tool that lowers the barrier to entry for non-Haskellers. As we've discussed before, FP Complete has done quite a bit of research on this topic, and the data shows that build tool issues have been an obstacle to adoption. We want stack to solve that, and we want your help.

Firstly: keep doing what you've been doing! Using stack, testing it, providing feedback, reporting bugs; all of these make stack better for both our existing community and for newcomers. But the next step is marketing Haskell outside of our community. All of us Haskellers already know how wonderful a language Haskell is. Let's send a clear message to the rest of the world that it's time they try Haskell. stack's aim is to remove those initial barriers. But now we need to tell people what Haskell has to offer.

If you're interested in getting involved in this kind of a push, please join and discuss on the Commercial Haskell mailing list. There's no preexisting formula for how this should be done. But the basic idea I have right now is:

  • Give users a clear message on how to get up and running with Haskell based on stack
  • Give a good example of a strength Haskell has
  • Make it easy for people to play around with the concept with some sample code

I'm sure others will have better ideas than I on how to accomplish this. If you want to see Haskell take off as not only a successful, powerful language (which it is now), but as a more popular language too, come get involved!

Categories: Offsite Blogs

Haskell Generics and Java Reflection

Haskell on Reddit - Mon, 06/22/2015 - 7:53pm

I stumbled on Haskell's Generics and it kind of reminds me of Java's Reflection mechanism. Not exactly the same mechanics in play, but both are trying to "solve" the same problem. Did I get it right?

submitted by evohunz
[link] [6 comments]
Categories: Incoming News