[Demonstration]
Hi guys! Today we will be studying about Haskell! This tutorial is created by Ayumilove.
First, how do we write a comment in Haskell?
To do this, we simply use these two symbols { - -} and the comment is placed between them. Like this!
Haskell script/code is written in notepad and later processed using an application called Winhugs or GHCI which can be downloaded from http://haskell.org
First, we learn some basics on how haskell script works
-- The 2 dashes in this line is symbol for 1 line comment!
-- Haskell is all about functional programming
-- Defining them and creating a function/action
--Let us create a script to add two integers/numbers ^_^
-- We need a function name, lets called it as addNumber
-- The : : semicolon symbol means define data type
-- Data type could be Int (integer), Double, Boolean, etc
addNumber : : Int -> Int -> Int
-- The code above means first int plus second int equals result (int)
-- Simply right?
If you have three numbers to add up together, simply
addNumber : : Int -> Int -> Int -> Int
three integers sum up equals to one output, which us Integer Int refers to Integer/Number (round number)
REMINDER!!! The data type starts with CAPITAL letter
int = wrong
INT = wrong
Int = right
addNumber : : Int -> Int _> Int
addNumber a b = a+b
-- Now we need to make a script
-- The script tells Haskell to add numbers
-- The above script is completed! There you have it
-- Yeah. I know, pretty forward like math
-- a and b represents variable (temporary storage)
-- This a and b are user input values
-- This script will automatically display the result
-- In C/C++/C# programming language, it requires user
-- To write code to print out/display the result.
-- Haskell does not need you to do it.
-- Another thing is Haskell is lazy function, meaning that it only do this function when it is being called.
-- It will not do the calculation during compilation.
-- One great advantage is that you can have infinite array so your system will not jam/pause/hang.
-- When you ask Haskell to extract one portion of the data from the array, it only do that part, checks that part.
-- Let us test out the program!
-- Save as as .hs (Haskell script) and set to “All Files”
-- If you are using winhugs, just drag the file into the application.
Transcription by:
Scribe4you Transcription Services