Do you want a more expressive and concise programming language? A language that catches more of your bugs at compile time, before they cause problems? A language with a fresh perspective that will change the way you think about programming? Meet Haskell! Haskell is an efficient and mature functional programming language that has, for the past quarter century, been pushing the boundaries of what a programming language can do. In this course you will learn the basics of Haskell, as well as some of the features that set Haskell apart from the multitude of other programming languages. No prior experience with functional programming is required for this course.
Introduction Hello. This is Benson Joeris. Welcome to Haskell Fundamentals. In this course, you will learn the basics of Haskell, one of the most exciting, cutting-edge, functional programming languages out there. The goal of this course is for you to be able to write simple Haskell programs and have enough background in the core concepts of the language to be able to figure out more advanced topics as you need them later. I think most people watching this course will know at least a little bit of programming in some other language, but you certainly do not need to know anything about functional programming or anything else related to Haskell. Really all you need for this course is some curiosity and a willingness to learn something new and different. Since you're watching this video, you've probably at least heard the name Haskell before, but this first module will give you a very high-level overview of what you're getting into. I'm going to tell you very roughly what makes Haskell a unique and powerful programming language and why you really want to learn Haskell. Haskell comes from a very different background than most other programming languages and I will share a little bit of that history to help give you some context. Finally, I'll tell you about the tools you'll need for the rest of the course.
Functions Hello. This is Benson Joeris. Welcome to this module on Functions in Haskell. As a functional language absolutely everything in Haskell revolves around functions. They're Haskell's beating heart and the building blocks of every Haskell program. I'll start off by showing you the syntax for calling and defining functions in Haskell, which looks a little different than other languages you might be familiar with. I'll tell you about some very surprising things that Haskell functions can't do involving the notion of function purity. Next, I'll tell you about recursion. You may already be familiar with recursion and imperative languages, but recursion in functional programming is a much more important general tool than an imperative programming. I'll show you the two most important functional data structures, lists and tuples, and then I'll show you how you can use pattern matching to write concise, readable functions using data structures like lists and tuples. I'll also talk about the way Haskell handles local variables using the let and where keywords. Finally, I'll wrap up the module by telling you about one of the most unique, bizarre, and once you get your head around it, useful features in Haskell, Lazy Function Evaluation.
Higher Order Functions Hello. This is Benson Joeris. Welcome to this module in Higher-Order Functions in Haskell. In an imperative language like Java or C#, you were used to thinking about functions as a way to package together some instructions to help organize a program and reuse code. In Haskell and other functional languages, functions are much more fundamental. Functions in Haskell are just another type of value like int or string and this turns out to be extremely useful. In this module, you see some very useful functions that work by taking another function as an argument. These functions with function arguments turn out to be the easiest way to manipulate lists. You'll also see several ways to create functions on the fly including partial function application where you only provide some of the arguments to a function, lambda expressions, which define a short function in line right where it's needed, and function composition, which can combine two functions together to create a new function.
Types Hello and welcome back to this course on Haskell Fundamentals. In this module you will learn the basics of Haskell's type system. This type system is quite different and generally much more powerful than type systems and languages you might be familiar with like C or Java. I will only be able to touch the surface of what Haskell's type system is capable of. Many of the groundbreaking language innovations in Haskell are really features of the type system. First I will give you a brief overview of the Haskell type system and how it relates to other, more familiar type systems. Next I will show you how to use the GHCi REPL to explore the types of variables and functions in a program. You will see how to specify types explicitly and when you might want to do this. You will also see how Haskell infers types and why we haven't had to specify any types in the programs we've written up to now. Next I will introduce you to polymorphic functions, which are flexible about the types they can handle and can help reduce repeated code. Finally, I will show you type class constraints, these are one of innovations of Haskell's type system and make polymorphic functions much more useful.
Custom Types Welcome back to this course on Haskell Fundamentals. This module will teach you how to define and use your own custom data types in Haskell. Just like other languages, it's hard to get very far just using basic built in types like Ints or Strings without some custom, higher level types to tie them together, like customer, or image, or whatever else. I will cover several approaches that Haskell provides to create custom data types. The simplest way to create a new type is just to give a different, more convenient or meaningful name to a type that already exists. There's also newtype, which is very similar to a type synonym, but with the help of Haskell's powerful type system, newtype can help make code more expressive and robust. I will also cover Haskell's records, this is the closest thing Haskell has to a struct or class, and might be the most familiar and comfortable to use. Unfortunately records have some drawbacks and are not usually the best choice for composite data. The workhorse of custom types in Haskell is the algebraic data type. They are different from data structures you might be familiar with from other languages, and it can take a little while to get your head around them. However, algebraic data types are very powerful and can represent complex data in a concise, expressive manner.
Type Classes Hello and welcome back to this course on Haskell Fundamentals. This module will teach you how to effectively use type classes with your custom data types. You will learn how your types can support common functionality, like being equality comparable. First I will cover creating new type class instances for existing type classes in the standard library. This is how you say, my custom type is equality comparable, or my custom type is numeric. I will also show you a very easy way to define instances for certain, common type classes so you can say, my custom type is equality comparable in the obvious way. Then I will show you how to define a type class. This is the way standard type classes, like numeric, are implemented in the standard library, and also the way you can define new type classes to represent concepts specific to your program or domain. Finally, you'll see how type classes can be subclasses of one another, but don't let the terminology fool you, this has nothing to do with object-oriented inheritance.
IO Welcome to the final module of this course. You're going to learn about IO actions in Haskell. IO is Haskell's ingenious way for programs to interact with the outside world and do things without sacrificing function purity. This may be the easiest module in the course because the things you will see, like writing to the console, might appear very familiar. But this appearance is a complete illusion, and understanding what is actually going on makes this one of the most difficult parts of the course. First I'm going to show you how to compile your Haskell code into an executable program, you will finally get to write and run Hello World. Next, we will try to explore what this Hello World program actually does and how it is possible to print to the command line even though Haskell's pure functions are not allowed to have any side effects. You will learn how to combine IO actions together so that they run one after another. Then we will cover how to get values that depend on the external world, like reading a string from the console. Finally, we'll wrap things up by looking at a small selection of useful IO functions to get you started in writing your own Haskell programs.