Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Laboratory 6
Title of the Laboratory Exercise: Introductory exercises in Haskell
3. Experimental Procedure
Students are given a set of instructions to be executed on the computer. The instructions
should be edited and executed and documented by the student in the lab manual. They are
expected to answer questions posed in section 5 based on their experiment.
Ramaiah University of Applied Sciences
Private University Established in Karnataka State by Act No. 15 of 2013
Documentation:
a. Procedure and Algorithm(s): Procedure and analysis:
1. How different is this language from ‘C’ programming language?
C programming language is an imperative language, while Haskell
is purely a functional programming language. In imperative
programming, the computer is given a sequence of tasks and
executes them. The state of variables may get changed during the
execution. It basically describes how to solve a problem or task.
However, in functional programming languages like Haskell, what
needs to be accomplished is described, rather than how.
Functional programs are self-contained and stateless. The order of
execution is less important when compared to imperative
programming languages. While the primary flow control involves
loops, conditionals and function calls in languages like C, Haskell
uses function calls and recursion to control program flow.
While designing a program in Haskell, we evaluate functional
transformations and data collections.
There is no notion of variables in Haskell as it is in C.
It is easier to create lists and tuples in Haskell, while their
representative counterparts, arrays and structures take several
lines of code to define and use in C.
C is strictly typed, while Haskell is loosely typed, and C has several
types like byte, short, int and long to represent integer data, but
Haskell has just one.
It is possible to write conditions within expressions in Haskell, but
not in C.
Haskell has built in Boolean data type, but C doesn’t.
Haskell is much more concise, elegant and easier to maintain and
debug. Functional programs are shorter when compared to
imperative equivalents.
Ramaiah University of Applied Sciences
Private University Established in Karnataka State by Act No. 15 of 2013
Screenshot:
Discussion:
Here, in this part we are doing some basic math operations, some basic logical operations, using max min to
get the maximum and minimum of two numbers respectively and succ and pred to obtain successor and
predecessor of number respectively.
Here, we load the (*.hs) file and perform the following actions.
Ramaiah University of Applied Sciences
Private University Established in Karnataka State by Act No. 15 of 2013
Screenshot:
Discussion:
This screenshot represents the Working with (*.hs)file , head, tail, init, null, length, and reverse.
Here in first I got some error while loading .hs file so check the file content that you write the correct code.
Ramaiah University of Applied Sciences
Private University Established in Karnataka State by Act No. 15 of 2013
Screenshot:
Discussion:
This screenshot represents the working with some more commands like True, lists, take, drop, product etc.