haskell
Post on 22-Nov-2014
422 Views
Preview:
TRANSCRIPT
1
Individual assignment
APLC
HAND IN DATE: 15-08-2010
HAND OUT DATE: 09-11-2010
2
Geeta Nagpal Rahul Kumar
(Module Lecturer) (PT00782238)
Acknowledgement
Haskell is a modern ``purely functional'' programming language. A functional language is one in
which functions are as easy to manipulate as the more common kinds of values, such as numbers
and strings. By being purely functional, Haskell does not allow the operations which make
functions difficult to work with in traditional imperative languages: assignment to global
variables or reference parameters. As a result, calling a function will not have any ``side-
effects''--that is, it will not change the values of any non-local variables--and we are free to treat
them as pure functions.
The advantage of Haskell lies in the fact that it enables programmers to be more productive and
write shorter, clearer, and more maintainable code. Unfortunately, industry practice has not yet
embraced functional programming, in part because of the enormous effort it would take to retrain
current programmers and redesign all the support tools.
Objective-
The main objective is to implement a system that minimizes the processing time of the
employees of the bank by making core functionalities paper free. Present time there are many
banking software system available in the market but they are not so much effective as user
prospects in the terms of cost, speed, ease of use, proper interface, user-friendly etc. Proposed
system is very simple in terms of use any novice and casual user can also use this system easily.
Developed in pure functional programming, this system shall provide coding benefits but has a
few limitations, primarily due to lack of scope of the module.
3
4
Introduction-
It’s a well known fact that the productivity and the success of an organization depend
substantially on its technology the higher and effective technology drives any organization. The
better the technology better are the prospects for the organisation. In this fast and furious world
where every manual work is shifted towards computer work. And the time has become more
precious than money. People desire instant output from system. and maximum system’s output
based on its software system. Means how fast and accurate data we can access using the system.
This bank management software system is developed to avoid these things. So this software
would be suggesting the best result which would take less amount of time.
Objective-
The main objective to implement such software is to minimize the processing time of the
employee of the bank by getting an efficient and accurate result. Present time there are many
banking software system are available in the market but they are not so much effective as user
prospects in the terms of cost, speed, ease of use, proper interface, user-friendly etc. proposed
system is very simple in terms of use any novice and casual user can also use this system easily
after getting/understanding some instructions and one more advantage is it’s cost is not very high
in terms of maintenance and redevelopment.
Specification-
this project mainly specifies to develop a simple banking application using Haskell for
Functional Programming Concepts and Prolog for Logic Programming Concepts.As prolog
application system specifies to Create a set of Prolog rules which, given a set of basic facts
about a family tree, and to define family relationships through bloodlines.
As project specification there are 5 modules in Haskell application:-
Check account details-In this module user can check the details of his/her account in terms of
account ID, account number, name, gender and current balance in the account.
5
Money deposit-In this module user can deposit any amount of money in his/her account or
other’s account.
Money transfer-In this module user can send/transfer any amount of money to another’s
account in other case if there is no selected money in the account of the user then he/she is
unable to transfer money. for example if any user wants to transfer 5000/- rupees from his/her
account but there is only 2000/- rupees in his/her account then in this case he/she cannot transfer
the money.
Money withdraw-In this module user can withdraw any amount of money from his/her account
in other case if there is no sufficient balance is available in his/her account which he/she wants to
withdraw then he/she cannot withdraw money.
Create new account-In this module user can create a new account in the bank.
Requirement- The following are the list of those hardware and software resources that
required for developing and running the system -
Software requirement-
Win hugs
Swi-Prolog
Hardware requirement-
Processor: Preferably 1.0 GHz or Greater.
RAM : 128 MB or Greater.
Language used -
1. Haskell-
Haskell is a modern, standard, non-strict, purely-functional programming language. It
provides all the features including polymorphic typing, lazy evaluation and higher-order
functions. It also has an innovative type system which supports a systematic form of
overloading and a module system. It is specifically designed to handle a wide range of
6
applications, from numerical through to symbolic. To this end, Haskell has an expressive
syntax, and a rich variety of built-in data types, including arbitrary-precision integers and
rationales, as well as the more conventional integer, floating-point and Boolean types.
There are a number of compilers and interpreters available. First-time users may want to
start with Hugs, a small, portable Haskell interpreter. Haskell was named after the
logician Haskell B. Curry. Curry, together with Alonzo Church, laid the foundations of
functional computation in the era Before the Computer, around 1940. As a functional
programming language, Haskell is a member of the Lisp family. Others family members
are Scheme, ML, Occam, Clean. Haskell98 is intended as a standard for lazy functional
programming. Lazy functional programming is a programming style where arguments are
evaluated only when the value is actually needed.
Functional Programming-
C, Java, Pascal, and so on, are all imperative languages. They are "imperative" in the sense that
they consist of a sequence of commands, which are executed strictly one after the other. Haskell
is a functional language. A functional program is a single expression, which is executed by
evaluating the expression.
Anyone who has used a spreadsheet has experience of functional programming. In a spreadsheet,
one specifies the value of each cell in terms of the values of other cells. The focus is on what is
to be computed, not how it should be computed. The advantages of functional programming are:
Ease of understanding
No core dumps
Codes re-use
Strong glue
Powerful abstractions
Built-in memory management
Advantages of Haskell-
Substantially increased programmer productivity.
7
Shorter, clearer, and more maintainable code.
Fewer errors, higher reliability.
A smaller "semantic gap" between the programmer and the language.
Shorter lead times.
Haskell is a wide-spectrum language, suitable for a variety of applications. It is particularly
suitable for programs which need to be highly modifiable and maintainable.
2. Prolog-
Prolog is a non-procedural logic based language. Prolog involves building up a knowledge base (database) where relationships are represented. Prolog then uses a built-in facility in order to draw logical conclusions from a user's inputs. Prolog has its roots in formal logic, and unlike many other programming languages, Prolog is declarative: The program logic is expressed in terms of relations, represented as facts and rules. A computation is initiated by running a query over these relations. The language was first conceived by a group around Alain Colmerauer in Marseille, France, in the early 1970s and the first Prolog system was developed in 1972 by Colmerauer with Philippe Roussel.
Advantages-
Logic based languages are able to represent the real world more accurately.
Prolog is able to derive new rules from the existing rules contained within the knowledge
base.
Module wise source codes with comments and explanation-
Module Name-Welcome Page
Source Code-
module Start where
8
import CreateAccount
import Checkbal
import Deposit
import Trans
import Withdraw
main::IO()
main = do
putStrLn " ****** Welcome To BANK MANAGEMENT SYSTEM ****** "
putStrLn " 1. Create an Account." --Press 1 to create an account--
putStrLn " 2. Check Balance." --Press 2 to check the balance--
putStrLn " 3. Withdraw Ammount." --Press 3 to withdraw the amount--
putStrLn " 4. Deposit Ammount." --Press 4 to deposit the amount--
putStrLn " 5. Money Transfer." --Press 5 for money transfer--
putStrLn " "
putStrLn " "
putStr " Enter your Choice: "
choice<- getLine
menu choice
menu :: String -> IO ()
menu choice = case choice of
"1" -> account
"2" -> bal
9
"3" -> with
"4" -> depo
"5" -> tran
"0" -> main
_ ->do
putStrLn "Invalid Input..!!!! Please Try Again.!!"
Explanation- Working of this module-
Display startup page on the screen.
Text based user friendly menu and choice of options for user.
On choice making of user it will be forwarded to other section of application.
Use of higher order function.
Module Name-Create Account
Source Code-
module CreateAccount where
account :: IO()
account = do
as<-readFile "rahul.txt" --Database named rahul--
let as1 = length (func as)
putStrLn " Enter your Name : " --write your name--
a<-getLine
10
putStrLn " Enter your Address :" --write your address--
b<-getLine
putStrLn " Enter your Gender :" --write your gender m/f--
c<-getLine
putStrLn " Enter Balance :" --enter minimum balance to deposit--
d<-getLine
let d1 = read d:: Int
e<-readFile "rahul.txt" --entries comes in database--
let e1 = func e
let e2= e1 ++ [(as1+1,a,b,c,d1)]
writeFile "rahul.txt" (show e2)
func :: String -> [(Int,String,String,String,Int)]
func x =read x::[(Int,String,String,String,Int)]
Explanation-Working of this module:
Add new customers by filling details of customer.
Data takes as input in list of tuples.
Automatically generate customer account ID.
Module Name-Check balance
Source Code-
module Checkbal where
11
bal :: IO()
bal = do
x<-readFile "rahul.txt"
let x1 = func1 x
putStr " Enter Account Number : " --write your account number--
y<-getLine
let y1 = read y:: Int
let in2 = [(a,b,c,d,e)|(a,b,c,d,e)<-x1, a == y1]
let in3 = head in2
if(in2 == []) then do
putStrLn " "
putStrLn "Account Number Doesnot Exist..!!!! " -- display massage when entered account no does not match to any account number of data base--
else do
let z = func in3
putStr " Your Account Balance is :" --your current account balance--
putStrLn (show z)
func :: (Int,String,String,String,Int)->Int
func (a,b,c,d,e) = e
func1 :: String -> [(Int,String,String,String,Int)]
func1 x =read x::[(Int,String,String,String,Int)]
Explanation- Working of this module-
It gives the information about current balance.
12
It matches the customer ID of data base and entered customer ID by user if they not
match it shows a massage that record is not found.
Module Name-withdraw
Source Code-
module Withdraw where
with :: IO()
with = do
putStrLn "Enter Account Number : " --write your account number--
x<-getLine
let x1=read x :: Int
a<-readFile "rahul.txt" --data base matches account no--
let a1 = func a
let q = [(a,b,c,d,e)|(a,b,c,d,e)<-a1,a == x1]
let q1 = head q
let g = func1 q1
putStrLn "Enter the amount to be Withdrawn : " --write the amount to be withdraw--
z<-getLine
let z1=read z :: Int
if(z1>g) then do
putStrLn "Money Cannot be Withdrawn..!!" --display massage in the case of available amount<withdrawal amount--
else do
let f = g - z1
13
let qw = func2 q1 f
let qw1 = func3 qw
let c = [(a,b,c,d,e)|(a,b,c,d,e)<-a1,a/=x1]
let d1 = c ++ qw1
writeFile "rahul.txt" (show d1)
func :: String -> [(Int,String,String,String,Int)]
func x =read x::[(Int,String,String,String,Int)]
func1 :: (Int,String,String,String,Int)->Int
func1 (a,b,c,d,e) = e
func2 :: (Int,String,String,String,Int) -> Int -> (Int,String,String,String,Int)
func2 (a,b,c,d,e) x = (a,b,c,d,x)
func3 :: (Int,String,String,String,Int) -> [(Int,String,String,String,Int)]
func3 (a,b,c,d,e) = [(a,b,c,d,e)]
Explanation- Working of this module-
Allows user to withdraw money from his/her account.
Check available balance and withdrawal balance if available balance <withdrawal
balance, it gives massage insufficient balance.
Module Name-Deposit
Source Code-
depo :: IO()
depo = do
putStr " Enter Account Number : "
x<-getLine
14
let y = read x:: Int
in11<-readFile "rahul.txt" --database--
let in1 = func in11
let in2 = [(a,b,c,d,e)|(a,b,c,d,e)<-in1, a == y]
let in3 = head in2
let g = func1 in3
putStr " Enter Ammount to be deposit : " --write amount here --
z<-getLine
let y1 = read z:: Int
let u = g + y1
let in4 = func2 in3 u
let in41 = func3 in4
putStr" Amount after Deposit is : " --new account balance(last amount+deposited amount)--
putStrLn (show (func1 in4))
let in5 = [(a,b,c,d,e)|(a,b,c,d,e)<-in1, a /= y]
let in6 = in5 ++ in41
writeFile "rahul.txt" (show in6) --new database entry--
func :: String -> [(Int,String,String,String,Int)]
func x =read x::[(Int,String,String,String,Int)]
func1 :: (Int,String,String,String,Int)->Int
func1 (a,b,c,d,e) = e
func2 :: (Int,String,String,String,Int) -> Int -> (Int,String,String,String,Int)
func2 (a,b,c,d,e) x = (a,b,c,d,x)
15
func3 :: (Int,String,String,String,Int) -> [(Int,String,String,String,Int)]
func3 (a,b,c,d,e) = [(a,b,c,d,e)]
Explanation- Working of this module-
It allows user to deposit money in any account using account ID.
If account deposit successfully completed the deposited amount will be automatically
added to available balance.
Module Name-Transfer
Source Code-
module Trans where
tran:: IO ()
tran = do
putStr " Enter the account number from where Money will be transfered : " --source account no--
x<-getLine
let x1 = read x::Int
putStr " Enter the account number where Money will be transfered to : " --destination account no--
y<-getLine
let y1 = read y::Int
putStrLn " "
putStr " Enter the Ammount to be transfered : "
z<-getLine
let z1 = read z::Int
16
func21 y1 z1
func11 y1 x1 z1
func11::Int->Int-> Int->IO()
func11 x y y1 = do
in11<-readFile "rahul.txt"
let in1 = func in11
let in21 = [(a,b,c,d,e)|(a,b,c,d,e)<-in1, a == x]
let in31 = head in21
let g1 = func1 in31
if(g1 < y1) then do
putStrLn" You Balance is Low " --display massage when available balance in source account is less than amount to be transfer--
else do
let in2 = [(a,b,c,d,e)|(a,b,c,d,e)<-in1, a == y]
let in3 = head in2
let g = func1 in3
let u = g + y1
let in4 = func2 in3 u
let in41 = func3 in4
putStr" Amount after withdraw of Money is in Account Number " --new amount in source account--
putStr (show y)
putStr" is : "
17
putStrLn (show (func1 in4))
let in5 = [(a,b,c,d,e)|(a,b,c,d,e)<-in1, a /= y]
let in6 = in5 ++ in41
writeFile "rahul.txt" (show in6) --database is updated--
func21 :: Int->Int->IO()
func21 y y1 = do
in11<-readFile "rahul.txt"
let in1 = func in11
let in2 = [(a,b,c,d,e)|(a,b,c,d,e)<-in1, a == y]
let in3 = head in2
let g = func1 in3
if(g < y1) then do
putStrLn " "
putStrLn " Money Cannot Be Transfered"
else do
let u = g - y1
let in4 = func2 in3 u
let in41 = func3 in4
putStrLn " "
putStr" Amount after Deposit of Money is in Account Number " --new balance in destination account--
putStr (show y)
putStr" is : "
18
putStrLn (show (func1 in4))
let in5 = [(a,b,c,d,e)|(a,b,c,d,e)<-in1, a /= y]
let in6 = in5 ++ in41
writeFile "rahul.txt" (show in6)
func :: String -> [(Int,String,String,String,Int)]
func x =read x::[(Int,String,String,String,Int)]
func1 :: (Int,String,String,String,Int)->Int
func1 (a,b,c,d,e) = e
func2 :: (Int,String,String,String,Int) -> Int -> (Int,String,String,String,Int)
func2 (a,b,c,d,e) x = (a,b,c,d,x)
func3 :: (Int,String,String,String,Int) -> [(Int,String,String,String,Int)]
func3 (a,b,c,d,e) = [(a,b,c,d,e)]
Explanation- Working of this module-
It transfer money from one account to another account and automatically changes the
values of both account.
19
Screen shots- Main Menu-
Deposit module-
20
Check balance module-
Create Account Module-
21
Withdraw Module-
Transfer Module-
22
Testing-
Testing is the process of exercising software with the intent of finding and correcting errors. This
fundamental doesn’t change for the stand alone systems but the search for the errors is a
significant challenge for the software engineers due to the complex nature of the system. Testing
is
A process of finding error
Finding Undiscovered error
Unit Testing:-
Unit testing is a testing in which the individual units of the software are tested in isolation
from other parts of a program. It is type of testing for which we test the all type of the module
that is working according to need or not.
Advantages:
To catch the defects that occurs at the early stage of software development.
To minimize the ration of defects before moving to next level.
Integration Testing:-
Integration is a systematic approach to building the complete software structure specified
in the design from unit-tested modules.
Integration plan must specify the order in which the modules are integrated.
23
Test Plan of Application-
Module to be Tested Name of Tester Result Selected Test Plan
Pass Fail
Create account Rahul Kumar Unit Testing
Withdraw Rahul Kumar Unit Testing
Deposit Rahul Kumar Unit Testing
Transfer Rahul Kumar Unit Testing
Check Balance Rahul Kumar Unit Testing
Full System Rahul Kumar Integration Testing
Limitations –
There are many limitations in this application which can cause the failure of present system the
main limitation of this project is ,there is no modify account module in this application it can
cause many problems for user for example if user want to modify his/her name, address, phone
number in his/her account detail then it is not possible, the another problem is there is no delete
account option in this application another problems are there is no interactive screen ,security
system like data encryption technique, data hiding used in this application.
Future Enhancement-
To make this application more reliable and secure it is important to implement security, modify
and delete option in the application.
24
Prolog-
Facts
father(Rahul,Ram).
father(Rahul,Shewta).
father(Abhishak,Raju).
father(Abhishak,Deepti).
father(Ram,Kundan).
father(Ram,Rashmi).
father(Raju,Nitin).
father(Raju,Sneha).
mother(Akshita,Ram).
mother(Akshita,Shewta).
mother(Arinita,Raju).
mother(Arinita,Deepti).
mother(Deepti,Kundan).
mother(Deepti,Rashmi).
mother(Shweta,Nitin).
mother(Shweta,Sneha).
male(Rahul).
male(Abhishak).
male(Ram).
male(Raju).
male(Kndanu).
male(Nitin).
25
female(Akshita).
female(Arinita).
female(Shweta).
female(Deepti).
female(Rashmi).
female(Sneha).
Rules-
brother(X,Y):-male(X),father(F,X),father(F,Y),X\==Y.
sister(X,Y):-female(X),father(F,X),father(F,Y),X\==Y.
son(X,Y):-(father(Y,X);mother(Y,X)),male(X).
daughter(X,Y):-(father(Y,X);mother(Y,X)),female(X).
children(X,Y):-father(Y,X);mother(Y,X).
uncle(X,Y):-brother(X,F),father(F,Y).
parent(X,Y):-father(X,Y);mother(X,Y).
wife(X,Y):-father(Y,C),mother(X,C),x \= Y.
grandfather(X,Y):-father(X,S),father(S,Y),male(X).
grandmother(X,Y):-mother(X,S),father(S,Y),female(X).
brother-in-law(X,Y):-brother(X,W),wife(W,Y).
sister-in-law(X,Y):-sister(X,W),wife(W,Y).
QUERIES –
brother(X,Y)
sister(X,Y)
son(X,Y)
daughter(X,Y)
children(X,Y)
uncle(X,Y)
26
parent(X,Y)
wife(X,Y)
grandfather(X,Y)
grandmother(X,Y)
brother-in-law(X,Y)
sister-in-law(X,Y)
Learning objectives-
Throughout the development of the project the primary concern is to study the Haskell and
Prolog thoroughly. It will also help in understanding the blood relationship model and functional
programming language. Combining these two things and giving a fruitful result it was
accomplished by a good knowledge. So I have to pay attention on each and every part of Haskell
and Prolog.
Conclusion- Before completing the project I would like to conclude that, designing and
developing a bank management system was a real learning experience for me. The principles of
Haskell and Prolog were well implemented throughout the system. The whole project phase was
full of enthusiasm and joyous moments. I have successfully developed programs as required by
the project and have imparted all of the efforts to submit the project on time.
top related