# Haskell 102 Lecture Notes

DevFeed: [Haskell 102 Lecture Notes](<https://devfeed.tech/articles/haskell-102-lecture-notes-27924.md>)

Original publisher: [Read original article](<http://alt-romes.github.io/posts/lectures/2022-05-08-lecture-2.html>)

Published: 2022-05-08T00:00:00Z

Content type: tutorial

Language: en

Sources: [Romes' Musings](<https://devfeed.tech/sources/romes-musings.md>)

Topics: [Haskell](<https://devfeed.tech/topics/haskell.md>), [Functional programming](<https://devfeed.tech/topics/functional-programming.md>), [Programming](<https://devfeed.tech/topics/programming.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [function](<https://devfeed.tech/tags/function.md>), [functional-programming](<https://devfeed.tech/tags/functional-programming.md>), [haskell](<https://devfeed.tech/tags/haskell.md>), [programming](<https://devfeed.tech/tags/programming.md>), [programming-languages](<https://devfeed.tech/tags/programming-languages.md>), [types](<https://devfeed.tech/tags/types.md>)

## AI overview

Lecture notes introducing Haskell function types, currying, partial application, higher-order functions, laziness, recursion, recursive data structures, and type classes.

## Source excerpt

Contents 1 Functions Types, Currying, Partial application, Higher-order functions 2 Laziness 3 Recursion: Inductive Method 4 Recursive data structures 5 Type Classes 6 Type Classes Kinds, Constraints 1 Functions Types, Currying, Partial application, Higher-order functions All functions have a type, the function type: length :: [a] -> Int length [] = 0 length (x:xs) = 1 + length xs The same way we think about the Either type constructor, and about the tuple type constructor (,), we can think about the function type type constructor (the arrow ->). They are all type constructors that take two arguments. data Either a b = Left a | Right b data (,) a b = (a, b) -- pseudo code data (->) a b = a -> b -- pseudo code This means that the (->) type constructor, when applied to two types a and b, creates a new type a -> b, where a is the input type and b the return type. This beggets the question, what is the type of a function that takes two arguments? There are two ways to define multi-argument functions. The first would be to think about functions that receive multiple arguments in a tuple. prepend :: (Char, String) -> String prepend (c, str) = c:str You could even use it like this prepend('h', "ello"), which somewhat resembles the imperative style function call. The second option is to have a function take one argument a, and return a function that takes another argument b and only then returns c. prepend :: Char -> (String -> String) prepend c = (\str -> c:str) And this is the most common way to have multi-argument functions in functional programming languages. In Haskell, thinking about two argument functions and functions that return functions is really the same thing. The most common way of writing the two argument function prepend in Haskell, read "prepend is a function that takes two arguments of type Char and String and returns String", would be prepend :: Char -> String -> String prepend c str = c:str The (Char, String) -> String version is said to be an uncurried