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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

- 102 -LIST_EQUAL (TAIL [2,3]) (TAIL [2,4]) -> ... ->LIST_EQUAL [3] [4] -> ... ->{ EQUAL (HEAD [3]) (HEAD [4])) -> ... ->EQUAL 3 4 -> ... ->FALSE}FALSE6.10. StringsStrings are the basis of text processing in many languages. Some provide strings as a distinct type, for exampleBASIC and ML. Others base strings on arrays of characters, for example Pascal and C. Here we will introduce stringsas linear lists of characters.We can define a test for stringness:ISSTRING [] = TRUEISSTRING (H::T) = (ISCHAR H) AND (ISSTRING T)For example:ISSTRING [’a’,’p’,’e’] -> ... ->(ISCHAR ’a’) AND(ISSTRING [’p’,’e’]) -> ... ->(ISCHAR ’a’) AND((ISCHAR ’p’) AND(ISSTRING [’e’])) -> ... ->(ISCHAR ’a’) AND((ISCHAR ’p’) AND((ISCHAR ’e’) AND(ISSTRING []))) -> ... ->(ISCHAR ’a’) AND((ISCHAR ’p’) AND((ISCHAR ’e’) ANDTRUE) -> ... ->TRUEIn our notation, this function is:rec ISSTRING S =IF ISNIL STHEN TRUEELSE AND (ISCHAR (HEAD S)) (ISSTRING (TAIL S))We will represent a string as a sequence of characters within"Here is a string!"

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

Saved successfully!

Ooh no, something went wrong!