Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Hand In Date- 5th November 2012 Hand Out Date- 30th August 2012
SUBMITTED TO:
Ms. Geeta Nagpal (Module Lecturer)
APIIT SD INDIA
Page i
ACKNOWLEDGEMENT
First of all, I would like to express my powerful and largely under-rated thanks to my respected APLC faculty Ms. Geeta Nagpal for giving the possibility to complete this assignment with enthusiastic guidance and beneficial suggestions for improvement. Her help, support, valuable hints and encouragement motivated me a lot. I am also thankful to the library staff for providing me necessary books related to my project. I would like to thank APIIT SD INDIA, Panipat for giving me the opportunity to work in a pleasant environment and also supporting me directly or indirectly. I would also like to express our heartily gratitude to Prof. R. K. Chaudhary, Director APIIT SD INDIA for their sharing valuable time and knowledge and also for providing such facilities which had helped me to complete our assignment. At last, I am deeply indebted to express our sincere thanks to all staff members at APIIT SD INDIA, Panipat for their enthusiastic help which enabled me to complete my work.
Anuja ( PT0981136)
APIIT SD INDIA
Page ii
Certificate
This is to certify that Anuja (PT0981136) has submitted this Advanced Programming Language Concepts individual assignment for the partial fulfillment of seventh semester of B. E (Hons) degree course. She has successfully completed the project within specified duration, under the guidance of Ms. Geeta Nagpal (Project Supervisor) with full determination and Discipline.
APIIT SD INDIA
Page iii
ABSTRACT
The main objective of this module is to provide us knowledge about basics of functional and logical programming language concepts. Functional programming language being under study is Haskell where prolog as logical programming. The Haskell application is based on a Library Management System where user can check number of books available, borrowers of the book and the issue date. The application includes the use of databases and many functional programming concepts like higher order functions and recursion. The functionality of the system is divided in to five parts Find the no. of books and books name borrowed by the student Find the Borrowers of the book (Assuming more than one copy of any book) Find a book whether borrowed or not Find out the dates during which books borrowed by the student Calculate the overall fine for any student
As a librarian, user can create a new book record, create a student record, add a book, view the number of books available in library as well as calculate the fine charged to any student. In prolog application we have to create a set of Prolog rules for a given a set of basic facts and solve given queries. All the above functionalities have to use the list comprehension concept, recursion and higher order functions. Create a text based menu to handle these functionalities; recursion technique can be used in the text based menu.
APIIT SD INDIA
Page iv
INTRODUCTION
Functional programming is one the oldest of major programming paradigms. Functional programming is a programming paradigm that uses the functions in their real mathematical sense. This means that functions are only computation objects where there is no mutable data and state information. This way it is more close to mathematical expressions. In contrast to imperative programming that is desperately dependent on the state of the objects, functional programming views all programs as collections of functions that accept arguments and return values. Functional programming is so called because a program consists entirely of functions. The main program itself is written as a function which receives the programs input as its argument and delivers the programs output as its result.
Haskell is a general purpose, purely functional programming language incorporating many recent innovations in programming language design. Haskell provides higher-order functions, non-strict semantics, static polymorphic typing, user-defined algebraic data types, patternmatching, list comprehensions, a module system, a monadic I/O system, and a rich set of primitive data types, including lists, arrays, arbitrary and fixed precision integers, and floating-point numbers. Haskell has adopted many of the convenient syntactic structures that have become popular in functional programming.
APIIT SD INDIA
Page v
Map: applies the function passed to each element of the collection. Resembles to for each loops for collections in procedural languages. Filter: applies the filter function to each member of the collection and returns a list of object satisfying the conditional function. For Example: --Find whether a no is even
even1 :: Int->Bool even1 x=mod x 2==0 filt :: [Int]->[Int] filt x= filter even1 x
Recursion:
Recursion is actually a way of defining functions in which the function is applied inside its own definition. Recursion is one of the building blocks in functional programming. Since there is no other way for iteration in functional programming languages, it is the canonical and only way to implement iteration. Functional language implementations will often include tail call optimization to ensure that heavy recursion does not consume excessive memory.
Pattern matching:
Pattern matching is another powerful concept that functional and logic languages sport. It is used for assigning values to variables and for controlling the execution flow of a program. Pattern matching is used to match patterns with terms. If a pattern and term have the same shape then the match will succeed and any variables occurring in the pattern will be bound to the data structures which occur in the corresponding positions in the term.
APIIT SD INDIA
Page vi
List Comprehension:
List comprehensions are used to derive a new list from an existing list. For example: Input: [odd x | x <- [1...9]] Output: [True, False, True, False, True, False, True, False, True]
APIIT SD INDIA
Page vii
APIIT SD INDIA
Page viii
APIIT SD INDIA
Page ix
APIIT SD INDIA
Page x
APIIT SD INDIA
Page xi
APIIT SD INDIA
Page xii
SOURCE CODE:
import Data.Time type Book=String type Student=String type Date=(Integer,Int,Int) type Database = [(Book,Student,Date)] bookDb::Database bookDb=[("Haskell","Anuja",(2012,10,12)),("asp.net","Deepti",(2012,10,25)),("vb.net","See ma",(2012,10 ,6)),("Project Management","Sami",(2012,8,19))] lms:: IO() lms= do
APIIT SD INDIA
Page xiii
"putStrLn " @@ WELCOME TO LIBRARY MANAGEMENT SYSTEM @@@ putStrLn " Select Option ! putStrLn "Press 1 - Book Management" putStrLn "Press 2 - Borrower Management" putStrLn "Press 'q' to exit" menuopt menuopt:: IO() menuopt = do putStr "Enter your choice:" a<-getLine if a=="1" then bookmenu else if a=="2" then borrowmanage else putStrLn"Wrong Choice"
"
bkNum::String->Bool bkNum s=length (srchBr s)>0 bwbk::IO() APIIT SD INDIA Page xiv
putStrLn"***********BORROWER MANAGEMENT**********" putStrLn "Press- 1 Search Borrowed books & number" putStrLn "Press- 2 Search borrow dates" putStrLn "Press- 3 Calculate borrower fine" putStr "Enter your choice:" a<-getLine if a=="1" then fun1 else if a=="2" then fun2 else if a=="3" then fun3 else putStrLn"Wrong Choice" fun1::IO() fun1=do putStrLn"**********SEARCH BORROWED BOOKS & NUMBER**********" putStr "Enter the name of the student: " bk<-getLine putStr "Number of books borrowed:" putStrLn (show(length(srchBk bk))) //HIGHER ORDER FUNCTION putStr "List of books borrowed:" putStrLn (show(srchBk bk))
srchBk::String->[String] srchBk b=[x|(x,y,z)<-bookDb,y==b] brrwDt::String->[Date] brrwDt d=[z|(x,y,z)<-bookDb,y==d] fun2::IO() fun2=do putStrLn"**********SEARCH BORROW DATES**********" putStr "Enter the name of the student: " APIIT SD INDIA Page xv
exDate::String->String->[Date] exDate a b= [z|(x,y,z)<-bookDb,y==b && x==a] date :: IO (Integer,Int,Int) -- (year,month,day) date =do a<-getCurrentTime (return . toGregorian . utctDay) a
APIIT SD INDIA
Page xvi
No action needed.
No problem detected
No action needed.
APIIT SD INDIA
Page xvii
Test No 1
Expected Result
Actual Result
System should not allow Every student has two students to have given different and same student name. unique Id every time we entered student details.
Find the books borrowed (To check the book is borrowed or not)
Test No 1 Expected Result System should not allow entering wrong book details like book name. it must available in database Actual Result Fault Detected Action Taken No action needed.
Only those book No fault detected records can be seen which are available in the database.
Find the dates of books borrowed (To check the issue and return dates)
Test No 1 Expected Result Actual Result Fault Detected Action Taken No action needed.
System should not Only appropriate dates No fault detected consider wrong format of are taken into dates and it should be consideration. proper i.e. user cannot enter date above 31.
APIIT SD INDIA
Page xviii
APIIT SD INDIA
Page xix
Rule:
Query:
Q2 Fact:
Rule:
Query:
APIIT SD INDIA
Page xx
Limitations
The software developed is menu driven; in the age of graphical user interfaces the software should at least display some higher level of graphical user interactivity. The application will be used in a building in a standalone system. It may be shared so it can be used in libraries. The system can perform only one function at a time. It is not a secure application since it has no proper authentication and authorization. Any user with physical access can use the system. The system does not implement the concept of shared and dedicated databases. For record storage the old file systems are used. During operation of system user must take care of valid input otherwise he/she has to perform all action again. For example- if at some where data type matching not done then parser will send unidentified error.
The software is incapable of transferring data. The software is not able to provide secondary storage of books and students information or history file concept; as in after you exit the program limited information from memory is stored only in file.
APIIT SD INDIA
Page xxi
Transform the software to allow some client server architecture so that interaction increases.
For this Haskell must be browser supportable. Developer has to develop any kind of plugin so that it supported over browser.
How make this functional programming interoperable like XML. Research is still on way, if this is happening in near future then system can operate over any language platform.
There is no scope to catch some major errors. So enhancement can be done in many ways. It can be upgraded to an integrated system which will include all the possible users of the system such as administrator, user etc. Proper authentication and authorization Interoperability between different stores.
APIIT SD INDIA
Page xxii
APIIT SD INDIA
Page xxiii
Haskell - HaskellWiki. 2012. Haskell - HaskellWiki. [ONLINE] Available at:http://www.haskell.org. [Accessed 02 November 2012].
Input and Output - Learn You a Haskell for Great Good! 2012 [ONLINE] Available at: http://learnyouahaskell.com/input-and-output#files-and-streams. [Accessed 30 October 2012].
Power of Functional Programming, its Features and its Future | Coding Day. 2012. [ONLINE] Available at: http://www.codingday.com/power-of-functional-
Arizona, U, 2010, Comparative Programming language, Accessed from http://www.cs.arizona.edu/~collberg/Teaching/372/2010/Handouts/Handout-15.pdf, Accessed on 1st November 2012. Kantrowitz, M, 1997, Prolog Resource Guide, Accessed from http://www.cs.cmu.edu/Groups/AI/html/faqs/lang/prolog/prg/part1/faq.html, Accessed on 4th November 2012. Bezem, M, 1997, A Prolog Compendium, Accessed from http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/pt_framer.html, Accessed on 4th November 2012.
Reuben Thomas, 2000, Gentle Introduction to Haskell, version 98, [Online] Available from: http://www.haskell.org/tutorial/ [Accessed 31st October 2012]
APIIT SD INDIA
Page xxiv