Haskell is a computer programming language. In particular, it is a polymorphically statically typed, lazy, purely functional language, quite different from most other programming languages. The language is named for Haskell Brooks Curry, whose work in mathematical logic serves as a foundation for functional languages. Haskell is based on the lambda calculus, hence the lambda we use as a logo. 1 Why use Haskell? Writing large software systems that work is difficult and expensive. WOW! Even if you are not in a position to use Haskell in your programming projects, learning Haskell can make you a better programmer in any language. I learned Haskell a couple of years ago, having previously programmed in Python and (many) other languages. Haskell offers you: Substantially increased programmer productivity (Ericsson measured an improvement factor of between 9 and 25 using Erlang, a functional programming language similar to Haskell, in one set of experiments on telephony software). 3.4 Brevity
Hackage: IntroductionIntroduction - Learn You a Haskell for Great Good!About this tutorial Welcome to Learn You a Haskell for Great Good! If you're reading this, chances are you want to learn Haskell. I decided to write this because I wanted to solidify my own knowledge of Haskell and because I thought I could help people new to Haskell learn it from my perspective. This tutorial is aimed at people who have experience in imperative programming languages (C, C++, Java, Python …) but haven't programmed in a functional language before (Haskell, ML, OCaml …). The channel #haskell on the freenode network is a great place to ask questions if you're feeling stuck. I failed to learn Haskell approximately 2 times before finally grasping it because it all just seemed too weird to me and I didn't get it. So what's Haskell? Haskell is a purely functional programming language. Haskell is lazy. Haskell is statically typed. Haskell is elegant and concise. Haskell was made by some really smart guys (with PhDs). What you need to dive in A text editor and a Haskell compiler.
Haskell/Applicative functorsWhen covering the vital Functor and Monad type classes, we glossed over a third type class: Applicative, the class for applicative functors. Like monads, applicative functors are functors with extra laws and operations; in fact, Applicative is an intermediate class between Functor and Monad. Applicative are a widely used class with a wealth of applications (pardon the pun). Functor recap We will begin with a quick review of the Functor class chapter. class Functor f where fmap :: (a -> b) -> f a -> f b If a type has an instance of Functor, you can use fmap to apply a function to values in it. fmap id = id -- 1st functor lawfmap (g . f) = fmap g . fmap f -- 2nd functor law Maybe, for example, has a Functor instance, and so we can easily modify the value inside it... Prelude> fmap negate (Just 2)Just (-2) ...as long as it exists, of course. Prelude> fmap negate NothingNothing For extra convenience, fmap has an infix synonym, (<$>). Prelude> negate <$> Just 2Just (-2) The type of (<*>) is:
Haskell/The Functor classIn this chapter, we will introduce the important Functor type class. Motivation In Other data structures, we saw operations that apply to all elements of some grouped value. The prime example is map which works on lists. data Tree a = Leaf a | Branch (Tree a) (Tree a) deriving (Show) The map function we wrote for Tree was: treeMap :: (a -> b) -> Tree a -> Tree btreeMap f (Leaf x) = Leaf (f x)treeMap f (Branch left right) = Branch (treeMap f left) (treeMap f right) As discussed before, we can conceivably define a map-style function for any arbitrary data structure. When we first introduced map in Lists II, we went through the process of taking a very specific function for list elements and generalizing to show how map combines any appropriate function with all sorts of lists. Introducing Functor Functor is a Prelude class for types which can be mapped over. class Functor f where fmap :: (a -> b) -> f a -> f b The usage of the type variable f can look a little strange at first. Note
Haskell/Applicative functorsWhen covering the vital Functor and Monad type classes, we glossed over a third type class: Applicative, the class for applicative functors. Like monads, applicative functors are functors with extra laws and operations; in fact, Applicative is an intermediate class between Functor and Monad. Applicative are a widely used class with a wealth of applications (pardon the pun). It enables the eponymous applicative style, a convenient way of structuring functorial computations, and also provides means to express a number of important patterns. Functor recap We will begin with a quick review of the Functor class chapter. class Functor f where fmap :: (a -> b) -> f a -> f b If a type has an instance of Functor, you can use fmap to apply a function to values in it. fmap id = id -- 1st functor lawfmap (g . f) = fmap g . fmap f -- 2nd functor law Maybe, for example, has a Functor instance, and so we can easily modify the value inside it... Prelude> fmap negate (Just 2)Just (-2) Note Déja vu
post-rfc/sotu.md at master · Gabriel439/post-rfcThe functor design patternThis post builds on my previous post on the category design pattern and this time I will discuss the functor design pattern. If you are an intermediate Haskell programmer and you think you already understand functors, then think again, because I promise you this post will turn most of your preconceptions about functors on their head and show you how functors are much more powerful and generally applicable than you might realize. Mixing features So let's pretend that my previous post on categories inflamed your interest in compositional programming. Fortunately, programmers solve compatibility problems like this all the time. Typically, one category will be more featureful than the other, so the transformation is unidirectional. -- This "map"s an ordinary function to a monadic function map :: (Monad m) => (a -> b) -> (a -> m b) map f = return . f ... but we cannot write the reverse function and automatically map every monadic function to an ordinary function. Perfect! -- Smarter! Functors
The category design patternFunctional programming is all the rage these days, but in this post I want to emphasize that functional programming is a subset of a more important overarching programming paradigm: compositional programming. If you've ever used Unix pipes, you'll understand the importance and flexibility of composing small reusable programs to get powerful and emergent behaviors. Similarly, if you program functionally, you'll know how cool it is to compose a bunch of small reusable functions into a fully featured program. Category theory codifies this compositional style into a design pattern, the category. Moreover, category theory gives us a precise prescription for how to create our own abstractions that follow this design pattern: the category laws. One could easily dismiss this compositional ideal as just that: an ideal, something unsuitable for "real-world" scenarios. Categories I'm going to give a slightly different introduction to category theory than most people give. (f . g) . h = f . f . g . h
Haskell for Mainstream Programmers - StateSimon Peyton Jones touts Haskell as "the world's finest imperative programming language" and I strongly agree with that statement. In fact, I fell in love with Haskell precisely because of how elegantly it managed state so I decided to do a write-up of why I think Haskell got it right. Purity Haskell is a pure functional language, almost to a fault. This philosophy marks a significant departure from other functional programming languages like OCaml or Lisp. State Haskell solves the problem of stateful programming by replacing normal functional outputs with stateful outputs. -- actually a newtype, and I've flipped the output type State s a = s -> (a, s) In other words, a stateful output takes some old state of type s and returns the output of type a along with a new updated state of type s: old state output new state s -> ( a , s ) So if a pure function has the type: f :: a -> b ... then the "impure" stateful version would have the type: f' :: a -> State s b ... which just translates to: Yuck!