Skip to content

Instantly share code, notes, and snippets.

@Agnishom
Last active January 10, 2018 04:12
Show Gist options
  • Select an option

  • Save Agnishom/f056198c550d7782d088a7d53bb61150 to your computer and use it in GitHub Desktop.

Select an option

Save Agnishom/f056198c550d7782d088a7d53bb61150 to your computer and use it in GitHub Desktop.
Periodical Haskell Materials for Gregg

Episode 1

Objective: To understand the basic philosophy of Haskell, to know the distinction between functional programming and other paradigms of programming, setting up the haskell interpreter, getting acquinted to the basic syntax, basic understanding of the type system, currying

The Haskell Philosophy

Read any one of these (but not necessarily all three)

  • Prelude (CIS 194: Introduction to Haskell (Fall 2016))

    • Read the sections:
      • What is Haskell?
      • Themes
  • Introduction to Haskell (Haskell Wikibooks)

    • Read Sections 2 and 3:
      • What is functional programming?
      • What's good about functional programming?
  • Introduction (Learn You a Haskell)

Haskell Basics

Getting Set Up

Install the Haskell Interpreter

We'll try to talk more about build tools later

Variables, Functions, Truth Values

Getting some familiarity with the basic syntax and haskell patterns

Types

Types are central to the philosophy of Haskell

Episode 2

Objective: Being able to work with lists, through explicit recursion and also through functions like map, fold, filter. Some more familiarity with the Haskell Syntax and programming style

Lists

Lists are one of the most frequently used data structures in functional programming.

Some more Haskell Syntax and Basic Features

  • Control Structures - Haskell WikiBook
    • if-then-else, case expressions, guards
    • Ignore the part on actions for now
  • More on Functions - Haskell WikiBook
    • let, where, lambdas, sections

FollowUp 1

The Haskell Philosophy

See if you can answer these questions

  • Unlike imperative languages, there are no variable assignments and updates in Haskell. Why not?
  • Where are the while, for loops in Haskell?

Some Basic Problems

  • You may have seen the following definition for plus, for natural numbers, in one of the resources that I mentioned. In the same vein, define mult, in terms of plus. This is a toy exercise, just to get a feel of recursion
plus :: Int -> Int -> Int
plus n 0 = n
plus n m = succ (plus n (pred m))
  • Implement largestdiv :: Int -> Int which computes the largest divisor of a positive integer, other than itself.
  • Implement intReverse :: Int -> Int which reverses the digits of a given integer. For example, intReverse 496 is 694
  • Try the problems here

Types

  • It is considered good practice in Haskell to have written the type signatures of (almost) all the functions, even though the compiler can usually infer them. Can you tell why?
  • Explain the notation -> in gcd :: Int -> Int -> Int. Why are there multiple ->s?
  • Suppose f is a function, and g is a function, then f . g is their composition.
    • When can you compose two functions?
    • Can you write the code for . by yourself?
    • What should be the type of .?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment