-- isStringWithPatterns.hs: functions implementing the fsm in string-fsm.jpeg (this folder) -- This version uses patterns for function arguments -- The 'isString :: String -> Bool' line declares isString to be a function which takes -- a Haskell string and returns true if that string matches the FSM. -- Note: this code will fail if a character other than Q, a, or B appears in the string. -- Handling such input requires using "guards" in function definitions. isString :: String -> Bool isString chars = isStringStart chars isStringStart [] = False isStringStart ('Q':rest) = isStringMiddle rest isStringStart ('a':rest) = False isStringStart ('B':rest) = False isStringMiddle [] = False isStringMiddle ('a':rest) = isStringMiddle rest isStringMiddle ('Q':rest) = isDone rest isStringMiddle ('B':rest) = isEscape rest isEscape [] = False isEscape ('Q':rest) = isStringMiddle rest isEscape ('a':_) = False -- _ means "don't care" isEscape ('B':_) = False isDone text = null text