Select Page

What is Haskell?

Haskell is a functional language, whereas most popular programming languages are imperative languages. Imperative languages allow you to give a computer a set of instructions; the computer then executes them. Whereas with functional languages, you more so attempt to explain what things are and express them as functions.

Haskell Udemy Course Lessons 1 – 8

This course does seem reasonably up to date and might be a valuable learning tool. My main concern with all Udemy courses is that the material is old or isn’t up to date, and the code in the lessons is not compiling. Luckily with this course, I have yet to have any issues compiling code from the material. The courses’ is material is divided into three parts, and I can say that the first part 1/3rd of the course is an ode to functional programming: mainly the distinctions between functional programming and object-oriented programming. Although the first 4-5 lessons are about the installation process, and if you have Haskell installed are worth a skip.

Learn You a Haskell for Great Good! Chapters 1-2

The book starts by trying to comfort the reader and inform them that they might be exploring a language that is very different than other languages they may know and to have an open mind. The information on the Haskell install process is placed before the first chapter, then chapter One hits the ground running, covering topics a great number of topics. The first two chapters are a great introduction to Haskell, especially if the reader has previous programming experience. I enjoy the explanations, and the book does a great job of explaining the concepts in a manner that everyone can understand.

What I have learned

Key Takeaways of Most Functional Programming Languages

  1. avoid changing global state
  2. avoid mutating data
  3. avoid looping and employ recursion or high order abstractions
  4. Iteration concepts
    1. Traversal(mapping) 
    2. Reduction
    3. Filtering
    4. Composition

What separates Haskell from most Functional Programming Languages

  1. Functions are first-class values
  2. High-Order functions can be expressed elegantly
  3. Does not support standard loop control flow
  4. All about expressions and declarations
    1. meaning that the functions are used as values and then can be passed to other functions
-- Order of operations
-- Parentheses work the same way they do in basic math.
(4-1) * 3 
87 - (76 + 45)
-- Bool
-- Allows a variable to be either be True or False
-- "&&" means and while "||" means or
-- Both sides of the && need to be true have a true result
True && False 
True && True
-- Only one side of "||" needs to be true to have a true result
False || True 
not False
not True
-- Equality / Inquality operators
3 == 9 -- this statement reads 3 equals 9
6 == 6
5 /= 5 -- this statement read 5 not equals 5
5 /= 4
-- OfO

-- Bool


-- Equality

The basics are on par with most other languages, so I will mostly cover portions of the curriculum that are critical for my future success in learning the language. One of the significant differences that I have using Haskell for Mac is that the process for loading modules is entirely different. Haskell for Mac has a playground that is running at all times, so the need to load modules is a click of a button.

If Statements

One keynote to remember is that if statements in Haskell are an expression and they must return a value. So every “If” statement has a “then” and an “else”; otherwise, it will not run, which is very important to note.

Function x = if x > 10
                then x * 40
                else x + 40

Understanding Lists

In my journey, the concept that I enjoyed learning about the most is Lists. The way Haskell handles lists is so much easier on the user than managing a list in C# or an array in C++. Lists are a data structure where they contain a bunch of elements of the same type. Haskell makes it easy to use a list with several functions that serve the purpose of making list management easier. The ++ operator allows you to add to the end of a list and works with numbers and letters. Whereas the ” : ” operator allows you to add to the beginning of a list. Being able to concatenate a list easily is genuinely impressive and can’t be done with arrays.

concatNum = [4 , 8 , 15] ++ [16 , 23 , 42] 
concatWord = "Hello" ++ "World"

consOperatorWords ='A':" Small Cat"
consOperatorNums = 5:[1,2,3,4]

-- lists can be compared if they contain items that can be compared
-- it compares each item in lexiconal order
compareList = [3,4,2] < [3,4,3]

-- Other List Functions
--grabs the head item in a list
headOperator = head [1,2,3,4,5]
--grabs the last item in a list
tailOperator = tail [1,2,3,4,5]
--grabs everything except the very last item 
initOperator = init [1,2,3,4,5]
-- get the length
lengthOp = length [1,2,3,4]
nullCheck = null [1,2,3,4]
reverseList = reverse [1,2,3,4]
sumList = sum [1,2,3,4]
productList = product [1,2,3,4]

  "A Small Cat"


headOperator   1

tailOperator [2,3,4,5]

initOperator [1,2,3,4]

lengthOp  4
nullCheck  False
reverseList [4,3,2,1]
sumList  10
productList  24

Lists are great because you can not only put a list inside of a list, but you can also compare two lists, and easily access elements within a list based on their position. At this point, Haskell’s handling of lists is my favorite of any other language I have used.


Ranges take list creation to the next level. Instead of making a list of 1-8 the usual way and place every number in the list, you can just use a range to create the list. With Ranges you can also create steps where you can create a list where each number has steps between each number. This is useful when creating lists but has limitations, with the stepping process.

--Makes a list of 1 through 20  
range1 = [1..5]
range2 = ['a'..'d']

--you can make ranges with steps
steps = [2,4..10]
steps2 = ['b','d'..'n']
range1 [1,2,3,4,5]
range2 "abcd"

steps  [2,4,6,8,10]
steps2 "bdfhjln"

Until Next Time

So these are the concepts that I learned while going over the very first part of the material, but I understand that I have a long way to go. I feel like we covered, and going forward the concepts are only going to get more and more difficult. If I lose anyone on the feel free to comment because I really want to learn more about Haskell and helping others will in turn help cement the material for me. I believe that one I make it through the learning material, I will take some time to work on a small project. My goal is to make it through the learning material in the next six weeks. I believe that learning about functional programming will only further my ability to program in the future. I really hope you enjoyed learning Haskell with me, my goal is to have the next post out sooner now that I have a format for how I plan to write these posts. If you enjoy this type of content be sure to check my other posts discussing my journey into learning Haskell.