background preloader

Learn Haskell Fast and Hard

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 Related:  HaskellHaskell tutorialsHaskell

Why Do Monads Matter? « Sententia cdsmithus (A Side Note: I’ve been formulating the final thoughts on this post for about a week now. In an entirely unrelated coincidence, a good friend of mine and fellow Haskell programmer, Doug Beardsley, ended up writing two posts about monads over the weekend as well. Weird! Category Theory for Software Development? Match made in heaven? If you’re a software developer, have you heard about monads and wondered what they were? Or if you’re interested in mathematics, have you heard murmurs in the past about how category theory interests computer science people? These are the kinds of questions I begin with. Where category-based intuition and ideas, and monads in particular, come from in computer programming.Why the future of programming does lie in these ideas, and their omission in today’s mainstream languages has cost us dearly.What the state of the art looks like in applying category-based ideas to problems in computer programming. Ready? Quick quiz: Do computer programmers use functions?

Control.Monad.Writer | A Journal of Haskell Programming A QuickCheck Tutorial: Generators QuickCheck is a Haskell library for testing properties using randomly generated values. It's one of the most popular Haskell libraries and part of the reason why functional programming has mattered. In short, we can use functions to express properties about our programs and QuickCheck to test that such properties hold for large numbers of random cases. For example, given a function to reverse the elements of a list: reverse :: [a] -> [a] reverse [] = [] reverse (x:xs) = reverse xs ++ [x] We can define a property to check whether reversing a list (of integers) yields the same list or not: prop_ReverseReverseId :: [Integer] -> Boolprop_ReverseReverseId xs = reverse (reverse xs) == xs And QuickCheck will generate 100 lists and test that the property holds for all of them: ghci> quickCheck prop_ReverseReverseId +++ OK, passed 100 tests. If we define a property to check whether reversing a list once yields the same list or not (which holds only for some lists): generate :: Gen a -> IO a And roll it:

Making A Website With Haskell - adit.io 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. 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: cabal: Error: some packages failed to install: monad-logger-0.3.3.0 failed during the building phase. ExitFailure 1? Recap

A Gentle Introduction to Haskell, Version 98 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.

Mike's World-O-Programming - Yet Another Monad Tutorial (part 1: basics) It's a standing joke in the Haskell community that every Haskell programmer, as part of his or her learning process, will eventually write one or more monad tutorials. I'm certainly no exception. But since I know that there are already dozens of monad tutorials out there, some quite good, why on earth would I want to write Yet Another One? There are two reasons: I think I can explain some aspects of monads better than most of the monad tutorials I've seen.My own understanding of monads has improved greatly, and I'd like to try to pass that on if I can. Prerequisites Since I will be using the programming language Haskell in my examples, it would be very helpful if you, the reader, know Haskell up to and including polymorphic types and type classes. One prerequisite I will not be assuming is any knowledge of category theory, which is a very abstract branch of mathematics where the concept of a monad (as the term is used here) originated. Disclaimer Executive summary: What are monads? g (f x)

Haskell for all NICTA/course 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

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. 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 There are two completely separate namespaces in any Haskell source file: The value namespace, and the type namespace. Statements vs.

haskell - A monad is just a monoid in the category of endofunctors, what's the problem

Related:  ynaotoFP