background preloader

Haskell the hard way

Haskell the hard way
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

Monad Transformers Step by Step Information Martin Grabmüller: Monad Transformers Step by Step, draft paper, October 2006. 12 pages, A4 format, English. Abstract In this tutorial, we describe how to use monad transformers in order to incrementally add functionality to Haskell programs. It is not a paper about implementing transformers, but about using them to write elegant, clean and powerful programs in Haskell. Download This article is available electronically: [ PDF ] The source code of this article, in the form of a Literate Haskell script, is also available: [ Transformers.lhs ] BibTeX Entry @Unpublished{Grabmueller2006MonadTransformers, author = {Martin Grabm{\"u}ller}, title = {{Monad Transformers Step by Step}}, note = {Draft paper}, month = {October}, year = 2006, abstract = {In this tutorial, we describe how to use monad transformers in order to incrementally add functionality to Haskell programs.

(1) 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. If there are any errors or you think of a more illustrative example feel free to submit a pull request. 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: Laws

Haskell for all Haskell Lectures - CS 1501 Lecture 1 Outlines class structure, syllabus, grading policies, and reference text. Introduces the origin and theory behind Haskell. Lecture 2 Introduces Lists and Tuples, the most important data structures in Haskell. Lecture 3 Explores Haskell's strong Type system and Typeclasses. Lecture 4 Covers proper syntax in writing longer Haskell code. Lecture 5 Shows how to create your own data types to customize Haskell for you needs. Lecture 6 Investigates higher order functions such as maps, filters, folds, and a whole lot more.

sol/doctest-haskell dev.stephendiehl.com/hask/ Version 2.3 Stephen Diehl (@smdiehl ) This is the fourth draft of this document. License This code and text are dedicated to the public domain. You may copy and paste any code here verbatim into your codebase, wiki, blog, book or Haskell musical production as you see fit. PDF Version PDF Version Changelog Alternate Preludes (Updated)NumDecimals extensionutf8-stringfoundationbase64-bytestringsafe-exceptionsrecrusion-schemes (Updated)Data types a la carteCoerciblegenerics-sopZ3Time complexity for data structuresFingertreeVaultCryptography sectioncryptoniteentropymemoryCompression sectionlz4zlibDate & Time sectionhourglassServantNames for FreeAbstract Binding Treesde Bruijn Indiceswl-pprint-text (Updated)pretty-showAdjunctionsCartesian Closed CategoriesMonoidal CategoriesNew langauge comparisons (Koitlin, Lua, etc) Sections that have had been added or seen large changes: Cabal Historically Cabal had a component known as cabal-install that has largely been replaced by Stack. See: Stack Install Usage Vim

You Could Have Invented Monads! (And Maybe You Already Have.) If you hadn't guessed, this is about monads as they appear in pure functional programming languages like Haskell. They are closely related to the monads of category theory, but are not exactly the same because Haskell doesn't enforce the identities satisfied by categorical monads. Writing introductions to monads seems to have developed into an industry. There's a gentle Introduction, a Haskell Programmer's introduction with the advice "Don't Panic", an introduction for the "Working Haskell Programmer" and countless others that introduce monads as everything from a type of functor to a type of space suit. But all of these introduce monads as something esoteric in need of explanation. But what I want to argue is that they aren't esoteric at all. Many of the problems that monads try to solve are related to the issue of side effects. Side Effects: Debugging Pure Functions In an imperative programming language such as C++, functions behave nothing like the functions of mathematics. Solution and

Haskell from C: Where are the for Loops? | FP Complete If you're coming from a language like C, Haskell can take some getting used to. It's typical for a new language to feel a little different, but in Haskell the differences are more dramatic, and more fundamental. In particular... Where are the for loops? In most imperative languages, for loops are all over the place, and are used for a wide variety of different things. In Haskell, control structures are more expressive. Consider the simple example of computing the norm of a vector. Conceptually, there are three stages to this computation: mapSq: Square each elementsum: Compute the sumsqrt: Compute the square root We can think of the first step as building (at least abstractly) a new array whose ith element is y[i] = x[i] * x[i]. Putting everything in terms of functions, we can write this (in Haskell-like pseudocode) as norm(x) = sqrt(sum(mapSq(x))) , To clean up the syntax a bit, we can instead use the notation for function composition and write norm(x) = (sqrt ○ sum ○ mapSq)(x) , or just where

Gentle introduction to Haskell This is the master HTML version of the Gentle Introduction To Haskell, version 98. Revised June, 2000 by Reuben Thomas. You may download the following: Brief Table of Contents. All code in this tutorial, with additional commentary, is found in the code directory packaged with this tutorial. Premission is granted to correct, improve, or enhance this document. Copyright (C) 1999 Paul Hudak, John Peterson and Joseph Fasel Permission is hereby granted, free of charge, to any person obtaining a copy of "A Gentle Introduction to Haskell" (the Text), to deal in the Text without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Text, and to permit persons to whom the Text is furnished to do so, subject to the following condition: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Text.

lisperati.com/haskell/ 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.

Haskell for all: Introductions to advanced Haskell topics Many people bemoan the sharp divide between experts and beginning Haskell programmers. One thing I've noticed is that "advanced" Haskell topics all have one thing in common: there exists only one good tutorial on that topic and only the experts have found it. This post is a collection of links to what I consider to be the definitive tutorials on these topics. Monads Monads are technically not an advanced Haskell topic, but I include this topic in the list because the vast majority of monad tutorials are terrible and/or misleading. Monad Transformers One thing that perpetually boggles me is that the blogosphere has almost no posts explaining how to use monad transformers. Parsing Outsiders comment that monads only exist to paper over Haskell's weaknesses until they discover monadic parsers. You also want to understand parser combinators for another reason: Haskell parser combinator libraries are light-years ahead of Haskell regular expression libraries. Free Monads Coroutines Lenses Conclusion

Related: