background preloader

Try Haskell! An interactive tutorial in your browser

Try Haskell! An interactive tutorial in your browser

Haskell: The Confusing Parts If you’re used to the C family of languages, or the closely related family of “scripting languages,” Haskell’s syntax (mainly) is a bit baffling at first. For some people, it can even seem like it’s sneaking out from under you every time you think you understand it. This is sort of a FAQ for people who are new to Haskell, or scared away by its syntax. Use this as a cheat sheet, not a textbook. Misc. Stuff You Should Know Already Quick review, because if you’ve heard of Haskell, you should also have heard of most of this. foo :: Bar baz -> Bar quux is a type signature for the function foo, where Bar baz is the type of argument it takes, and Bar quux is the type of the return value. There’s no null and no void. Haskell’s syntax is indirectly based on ML, so if you stop reading here and go learn OCaml instead, some of this information will still be kinda useful. Type Names and Constructors The “has type” (::) operator can appear as an expression in parentheses, or a separate declaration.

Haskell Haskell is a functional programming language. If you are a seasoned programmer, consult the overview to see what makes Haskell unique and different from other languages. Haskell is distinct in a few ways: Haskell is pure. Haskell is enjoyable to use because dealing with pure functions makes code much easier to reason about, and the advanced type system helps catch silly and profound mistakes. Our aim in this book is to introduce you to the Haskell programming language — from the very basics to advanced features — and to computer programming in general. Overview[edit] The book is divided into a Beginner's Track, an Advanced Track, and a section called Haskell in Practice which covers more day-to-day issues and uses mostly items from the Beginner's Track. Search[edit] You may search the book here: Beginner's Track[edit] Our aim in this track is to introduce you to Haskell basics and some commonly used libraries. Advanced Track[edit] Haskell in Practice[edit] Appendices[edit] About the book[edit]

The Haskell Cheatsheet Beginning Haskell Before you start About this tutorial This tutorial targets programmers of imperative languages wanting to learn about functional programming in the language Haskell. In an introductory tutorial, many of Haskell's most powerful and complex features cannot be covered. The other significant element omitted in this tutorial is a discussion of monads, and therefore of I/O. Prerequisites This tutorial has no prerequisites. Back to top Haskell basics About Haskell Haskell is just one of a number of functional programming languages. Among functional languages, Haskell is in many ways the most idealized language. On a minor note, Haskell is syntactically easier to get a handle on than are the List-derived languages (especially for programmers who have used lightly punctuated languages like Python, TCL, and REXX). Obtaining Haskell Haskell has several implementations for multiple platforms. Taking the vows Giving things up No mutable variables Isolate side-effects No loops No program order Defining functions

Learn Haskell Fast and Hard I really believe all developers should learn Haskell. I don’t think everyone needs to be super Haskell ninjas, but they should at least discover what Haskell has to offer. Learning Haskell opens your mind. Mainstream languages share the same foundations: variablesloopspointersdata structures, objects and classes (for most) Haskell is very different. But learning Haskell can be hard. This article will certainly be hard to follow. The conventional method to learning Haskell is to read two books. In contrast, this article is a very brief and dense overview of all major aspects of Haskell. The article contains five parts: Introduction: a short example to show Haskell can be friendly.Basic Haskell: Haskell syntax, and some essential notions.Hard Difficulty Part: Functional style; a progressive example, from imperative to functional styleTypes; types and a standard binary tree exampleInfinite Structure; manipulate an infinite binary tree! 01_basic/10_Introduction/00_hello_world.lhs Introduction ou

Making A Website With Haskell - This is a guide to building and deploying a simple website using Haskell. We will use: Scotty for the backend Blaze-html for templating and Persistent for the ORM. Scotty is Haskell’s version of Sinatra. It also uses the same web server as Yesod (Warp) so it’s quite fast. Getting set up Before we start, here’s how I like to set up a Haskell project: 1. This creates an isolated environment and prevents you from running into dependency hell. To use a Cabal sandbox, you need Cabal version 1.18+. cd project_dir cabal sandbox init That’s it! 2. Here’s a simple one you can use (save it as todo.cabal): Hello World Save this as Main.hs: {-# LANGUAGE OverloadedStrings #-} import Web.Scotty main = scotty 3000 $ do get "/" $ do html "Hello World!" Now make and run it: cabal install .cabal-sandbox/bin/todo Go to and you should see your new Haskell site! Troubleshooting You might see a build failure with a cryptic message…something like: ExitFailure 1? Recap So what did we do? Routing Templates Stephen Diehl (@smdiehl ) Since I wrote these slides for a little user group talk I gave two years ago they have become a surprisingly popular reference. I decided to actually turn them into a proper skimmable reference for intermediate level Haskell topics that don't necessarily have great coverage or that tend be somewhat opaque as to where to get going, and then aggregate a bunch of the best external resources for diving into those subjects with more depth. Hopefully it still captures the "no bullshit brain dump" style that seemed to be liked. The source for all snippets is available here. To start a new Haskell project run $ cabal init $ cabal configure A .cabal file will be created. Sandboxes ( in cabal > 1.8 ) are self contained environments of Haskell packages. $ cabal sandbox init To update the package index from Hackage. $ cabal update To install the dependencies for the package: $ cabal install --only-dependencies To run the "executable" for a library under the cabal sandbox: Exceptions There's other tutorials out there, but you'll like this one the best for sure: You can just cut and paste the code from this tutorial bit by bit, and in the process, your new program will create magically create more and more cool graphics along the way... The final program will have less than 100 lines of Haskell[1] and will organize a mass picnic in an arbitrarily-shaped public park map and will print pretty pictures showing where everyone should sit! (Here's what the final product will look like, if you're curious...) The code in this tutorial is a simplified version of the code I'm using to organize flash mob picnics for my art project, picnicmob... [1] - Lines of active code only, not counting optional function signatures.