CSC 398 Functional Programming: Instructor: Dr. Hao Wu Lecture 2 Haskell and Functional Programming
CSC 398 Functional Programming: Instructor: Dr. Hao Wu Lecture 2 Haskell and Functional Programming
Programming
Instructor: Dr. Hao W
Features of Haskell
Resources
• Haskell Website
https://www.haskell.org/
Installation
Installation on Mac
Open your Terminal and enter the following command (You need to follow the instructions
to install all necessary packages ):
cschxw071168:~ wuh2$ curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
Welcome to Haskell!
System requirements
Note: On OS X, in the course of running ghcup you will be given a dialog box to install the command line tools. Accept and the requirements will be
installed for you. You will then need to run the command again.
Installation on Mac
Installation on Windows
PS C:\WINDOWS\system32> Get-ExecutionPolicy
AllSigned
7 HaoWu,
Hao Wu, CSC
CSC 398
398 Functional
FunctionalProgramming
Programming Week 11
Week
Installation on Windows
8 HaoWu,
Hao Wu, CSC
CSC 398
398 Functional
FunctionalProgramming
Programming Week 11
Week
Installation on Windows
9 HaoWu,
Hao Wu, CSC
CSC 398
398 Functional
FunctionalProgramming
Programming Week 11
Week
Your First Haskell Code
GHCi
• Quit
cschxw071168:Scripts wuh2$ ghci
GHCi, version 8.10.4: https://www.haskell.org/ghc/ :? for help
Prelude> :quit
• Leaving GHCi.
Haskell Editor/IDE
• You can use VSCode as the editor and IDE for Haskel
• You can find a complete tutorial from the website
https://medium.com/@dogwith1eye/setting-up-haskell-in-vs-code-on-
macos-d2cc1ce9f60a
• Here are some plugins you need
-
Function
Types
expression value
(7-3)*2 4*2 8
evaluation
expression value
•
ipV horse ipV
evaluation
evaluation
ipH ( ipV )
•
ipH
value
Definitions
• General Syntax
name :: type
name = expression
• Example
•
size :: Integer
size = 12 + 13
Definitions
• names for functions and other values begin with a small lette
Function definitions
Integer Integer
n square n*n
• The first line declares the type of the thing being defined.
- “->” signifies this is a functio
• The second line gives the definition of the functio
- when square is applied to an unknown or variable n, then the result
is n*n
23 Hao Wu, CSC 398 Functional Programming Week 1
n
Function Definitions
the name
of the the types
function of the the types
being formal of result
defined parameters