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.

- 104 -STRING_EQUAL "og" "og" ==STRING_EQUAL (’o’::"g") (’o’::"g") -> ... ->STRING_EQUAL "g" "g" ==STRING_EQUAL (’g’::"") (’g’::"") -> ... ->STRING_EQUAL "" "" -> ... ->TRUEIn our notation:rec STRING_EQUAL S1 S2 =IF (ISNIL S1) AND (ISNIL S2)THEN TRUEELSEIF (ISNIL S1) OR (ISNIL S2)THEN FALSEELSEIF CHAR_EQUAL (HEAD S1) (HEAD S2)THEN STRING_EQUAL (TAIL S1) (TAIL S2)ELSE FALSESimilarly, one string comes before another if its empty and the other is not:STRING_LESS "" (C::S) = TRUESTRING_LESS (C::S) "" = FALSEor if the character in its head comes before the character in the others head:STRING_LESS (C1::S1) (C2::S2) = TRUEif CHAR_LESS C1 C2or the head characters are the same and the first string’s tail comes before the second string’s tail:STRING_LESS (C1::S1) (C2::S2) = (CHAR_EQUAL C1 C2) AND(STRING_LESS S1 S2)if NOT (CHAR_LESS C1 C2)For example:STRING_LESS "porridge" "pota<strong>to</strong>" ==STRING_LESS (’p’::"orridge") (’p’::"ota<strong>to</strong>") -> ... ->(CHAR_EQUAL ’p’ ’p’) AND(STRING_LESS "orridge" "ota<strong>to</strong>") ==(CHAR_EQUAL ’p’ ’p’) AND(STRING_LESS (’o’::"rridge") (’o’::"ta<strong>to</strong>")) -> ... ->(CHAR EQUAL ’p’ ’p’) AND((CHAR_EQUAL ’o’ ’o’) AND(STRING_LESS "rridge" "ta<strong>to</strong>")) ==(CHAR EQUAL ’p’ ’p’) AND((CHAR_EQUAL ’o’ ’o’) AND

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

Saved successfully!

Ooh no, something went wrong!