Learn You a Haskell for Great Good!: A Beginner's Guide

Learn You a Haskell for Great Good!: A Beginner's Guide

Language: English

Pages: 400

ISBN: 1593272839

Format: PDF / Kindle (mobi) / ePub

Learn You a Haskell for Great Good!: A Beginner's Guide

Language: English

Pages: 400

ISBN: 1593272839

Format: PDF / Kindle (mobi) / ePub


It's all in the name: Learn You a Haskell for Great Good! is a hilarious, illustrated guide to this complex functional language. Packed with the author's original artwork, pop culture references, and most importantly, useful example code, this book teaches functional fundamentals in a way you never thought possible.

You'll start with the kid stuff: basic syntax, recursion, types and type classes. Then once you've got the basics down, the real black belt master-class begins: you'll learn to use applicative functors, monads, zippers, and all the other mythical Haskell constructs you've only read about in storybooks.

As you work your way through the author's imaginative (and occasionally insane) examples, you'll learn to:

  • Laugh in the face of side effects as you wield purely functional programming techniques
  • Use the magic of Haskell's "laziness" to play with infinite sets of data
  • Organize your programs by creating your own types, type classes, and modules
  • Use Haskell's elegant input/output system to share the genius of your programs with the outside world

Short of eating the author's brain, you will not find a better way to learn this powerful language than reading Learn You a Haskell for Great Good!

Excerpt from the Introduction

Haskell is fun, and that’s what it’s all about!

This book is aimed at people who have experience programming in imperative languages—such as C++, Java, and Python—and now want to try out Haskell. But even if you don’t have any significant programming experience, I’ll bet a smart person like you will be able to follow along and learn Haskell.

My first reaction to Haskell was that the language was just too weird. But after getting over that initial hurdle, it was smooth sailing. Even if Haskell seems strange to you at first, don’t give up. Learning Haskell is almost like learning to program for the first time all over again. It’s fun, and it forces you to think differently.

NOTE
If you ever get really stuck, the IRC channel #haskell on the freenode network is a great place to ask questions. The people there tend to be nice, patient, and understanding. They’re a great resource for Haskell newbies.

So, What's Haskell?

Haskell is a purely functional programming language.

In imperative programming languages, you give the computer a sequence of tasks, which it then executes. While executing them, the computer can change state. For instance, you can set the variable a to 5 and then do some stuff that might change the value of a. There are also flow-control structures for executing instructions several times, such as for and while loops.

Purely functional programming is different. You don’t tell the computer what to do—you tell it what stuff is. For instance, you can tell the computer that the factorial of a number is the product of every integer from 1 to that number or that the sum of a list of numbers is the first number plus the sum of the remaining numbers. You can express both of these operations as functions.

> Read the Introduction (PDF) in its entirety.

Learning Django Web Development

Ruby on Rails 3 Tutorial: Learn Rails by Example

Build Awesome Command-Line Applications in Ruby: Control Your Computer, Simplify Your Life

NSHipster: Obscure Topics in Cocoa & Objective C

Essential Matlab for Engineers and Scientists (4th Edition)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

source code of some modules will give you a solid feel for Haskell. Modules 89 Solving Problems with Module Functions The modules in the standard libraries provide many functions that can make our lives easier when coding in Haskell. Let’s look at some examples of how to use functions from various Haskell modules to solve problems. Counting Words Suppose we have a string that contains a bunch of words, and we want to know how many times each word appears in the string. The first module

pretty much the inverse type class of Show. It’s for converting strings to values of our type. Remember though, that when we use the read function, we might need to use an explicit type annotation to tell Haskell 124 Chapter 7 which type we want to get as a result. To demonstrate this, let’s put a string that represents a person in a script and then load that script in GHCi: mysteryDude = "Person { firstName =\"Michael\"" ++ ", lastName =\"Diamond\"" ++ ", age = 43}" We wrote our string

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 APPLICATIVE FUNCTORS 175 177 178 179 180 181 183 184 185 186 190 190 193 194 195 198 199 201 203 204 205 207 208 209 211 212 215 217 Functors Redux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . I/O Actions As Functors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Functions As Functors . . . .

. . . . . . . . . . . . . . . 12 MONOIDS 243 Wrapping an Existing Type into a New Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using newtype to Make Type Class Instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . On newtype Laziness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . type vs. newtype vs. data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

takes a file handle that tells it which file to read from. In all other respects, they work the same. Just like getContents, hGetContents won’t attempt to read all the file at once and store it in memory but will read the content only as needed. This is really cool because we can treat contents as the whole content of the file, but it’s not really loaded in memory. So if this were a really huge file, doing hGetContents wouldn’t choke up our memory. Note the difference between a handle and the

Download sample

Download