Haskell Language

4 programming

4 programming

An advanced, purely functional programming language

Declarative, statically typed code.

Videos

Functional Reactive Programming for Musical User Interfaces by Paul Hudak

Conquering Hadoop with Haskell and Ozgun Ataman

Using Lenses to Structure State with Nathan Bouscal

GHCJS: Bringing Haskell to the Browser, by Luite Stegeman

JГјrgen Cito presents todo-example, a lightweight webapp in Haskell

Abstractions for the Functional Roboticist with Anthony Cowley

Statically typed

Every expression in Haskell has a type which is determined at compile time. All the types composed together by function application have to match up. If they don't, the program will be rejected by the compiler. Types become not only a form of guarantee, but a language for expressing the construction of programs.

All Haskell values have a type:

You have to pass the right type of values to functions, or the compiler will reject the program:

You can decode bytes into text:

But you cannot decode Text, which is already a vector of Unicode points:

Purely functional

Every function in Haskell is a function in the mathematical sense (i.e., "pure"). Even side-effecting IO operations are but a description of what to do, produced by pure code. There are no statements or instructions, only expressions which cannot mutate variables (local or global) nor access state like time or random numbers.

The following function takes an integer and returns an integer. By the type it cannot do any side-effects whatsoever, it cannot mutate any of its arguments.

The following string concatenation is okay:

The following string concatenation is a type error:

Because getLine has type IO String and not String , like "Name: " is. So by the type system you cannot mix and match purity with impurity.

Type inference

You don't have to explicitly write out every type in a Haskell program. Types will be inferred by unifying every type bidirectionally. However, you can write out types if you choose, or ask the compiler to write them for you for handy documentation.

This example has a type signature for every binding:

But you can just write:

You can also use inference to avoid wasting time explaining what you want:

Types give a parser specification for free, the following input is not accepted:

Concurrent

Haskell lends itself well to concurrent programming due to its explicit handling of effects. Its flagship compiler, GHC, comes with a high-performance parallel garbage collector and light-weight concurrency library containing a number of useful concurrency primitives and abstractions.

Easily launch threads and communicate with the standard library:

Use an asynchronous API for threads:

Atomic threading with software transactional memory:

Atomic transactions must be repeatable, so arbitrary IO is disabled in the type system:

Functions don't evaluate their arguments. This means that programs can compose together very well, with the ability to write control constructs (such as if/else) just by writing normal functions. The purity of Haskell code makes it easy to fuse chains of functions together, allowing for performance benefits.

Define control structures easily:

If you notice a repeated expression pattern, like

you can give this a name, like

and then use it with the same effect as the orginal expression.

Get code re-use by composing lazy functions. It's quite natural to express the any function by reusing the map and or functions:

Reuse the recursion patterns in map , filter , foldr , etc.

Open source contribution to Haskell is very active with a wide range of packages available on the public package servers.

There are 6,954 packages freely available. Here is a sample of the most common ones:

DataDog provides powerful, customizable 24/7 metrics and monitoring integration for all of Haskell.org, and complains loudly for us when things go wrong.

Fastly's Next Generation CDN provides low latency access for all of Haskell.org's downloads and highest traffic services, including the primary Hackage server, Haskell Platform downloads, and more.

Rackspace provides compute, storage, and networking resources, powering almost all of Haskell.org in several regions around the world.

Galois provides infrastructure, funds, administrative resources and has historically hosted critical Haskell.org infrastructure, as well as helping the Haskell community at large with their work.

DreamHost has teamed up to provide Haskell.org with redundant, scalable object-storage through their Dream Objects service.

Awake Networks is building a next generation network security and analytics platform. They are a proud sponsor of the Summer of Haskell and contribute broadly to the Haskell community.

Digital Asset provides Distributed Ledger solutions for financial institutions globally. They have developed a pure, typed, functional, domain specific language for writing contracts, called DAML. They are a proud sponsor of the Summer of Haskelland contribute broadly to the Haskell community.

Asahi Net is a Japanese Internet service provider that has been running stable systems for over 25 years. They are a proud sponsor of the Summer of Haskell, and contribute to the Japanese Haskell community.

Fugue Inc. radically simplifies cloud operations with its software-defined system for dynamically orchestrating and enforcing cloud infrastructure at scale. Fugue uses Haskell in its product and is proud to sponsor Summer of Haskell.

IOHK is a technology company committed to using peer-to-peer technologies to provide financial services to the three billion people who don't have them. They implement our first-principles cryptographic research in Haskell and are committed to the development of the Haskell ecosystem. IOHK is a sponsor of the Summer of Haskell.

Tweag I/O is a network of software innovation labs across Europe. They have shipped Haskell in anything from tiny web services to large high-performance compute clusters with custom hardware. Tweag is a sponsor of Summer of Haskell.

Leave a Reply

Your email address will not be published. Required fields are marked *