||----------------------------------------------------------------------|| 
||									||
||	Palindrome example, from lecture 21 November 1996		||
||									||
||	Since reverse is built into Miranda, I have had to rename it	||
||	rev here; alternatively you can just omit the definition of	||
||	reverse.							||
||                                                                      ||
||	Simon Thompson, December 1996					||
||                                                                      ||
||----------------------------------------------------------------------|| 

string == [char]

palin :: string -> bool

palin st = (rev st' = st')
	    where
	    st' = disregard st

rev :: [char] -> [char]

rev []     = []
rev (a:st) = rev st ++ [a]

disregard :: string -> string

disregard = change . remove

remove :: string -> string
change :: string -> string

remove []     = []
remove (a:st) = a : remove st   , if notPunct a
              =     remove st   , otherwise

notPunct ch = isLetter ch \/ isDigit ch

isLetter ch = ('a'<=ch<='z') \/ ('A'<=ch<='Z')
isDigit  ch = ('0'<=ch<='9')

change []     = []
change (a:st) = convert a : change st

convert :: char -> char

convert ch = decode (code ch + offset)  , if 'A' <= ch <= 'Z'
           = ch                         , otherwise
             where
             offset = code 'a' - code 'A'


