10.07.2015 Views

An Introduction to Functional Programming Through Lambda Calculus

An Introduction to Functional Programming Through Lambda Calculus

An Introduction to Functional Programming Through Lambda Calculus

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

- 186 -4) Write functions <strong>to</strong>:i) Extract the leftmost n letters from string s:- left 4 "goodbye";> "good" : stringii) Extract the rightmost n letters from string s:- right 3 "goodbye";> "bye" : stringiii) Extract n letters starting with the l’th letter from string s:- middle 2 5 "goodbye";> "by" : stringiv) Find the position of the first occurence of string s1 in string s2:- find "by" "goodbye";> 5 : int5) The train travelling east from Glasgow Queen’s Street <strong>to</strong> Edinburgh Waverly passes through Bishopbriggs,Lenzie, Croy, Polmont, Falkirk High, Linlithgow and Edinburgh Haymarket. These stations might berepresented by the data type:datatype station = Queens_Street | Bishopbriggs |Lenzie | Croy |Polmont | Falkirk_High |Linlithgow | Haymarket | Waverly;Write functions which return the station <strong>to</strong> the east or the west of a given station, for example:6) The data type:- east Croy;> Polmont : station- west Croy;> Lenzie : stationdatatype exp = add of exp * exp |diff of exp * exp |mult of exp * exp |quot of exp * exp |numb of int;might be used <strong>to</strong> represent strictly bracketed integer arithmetic expressions:so: ::= ( + ) |( - ) |( * ) |( / ) |

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!