Question: Define a Haskell function which analyzes regular expressions defined using this type. data RE a -- RE's over an alphabet defined by 'a' = Empty

Define a Haskell function which analyzes regular expressions defined using this type.
data RE a -- RE's over an alphabet defined by 'a' = Empty -- empty regular expression | Sym a -- match the given symbol | RE a :+: RE a -- concatenation of two regular expressions | RE a :|: RE a -- choice between two regular expressions | Rep (RE a) -- zero or more repetitions of a regular expression | Rep1 (RE a) -- one or more repetitions of a regular expression deriving (Show)
matchEmpty :: RE a -> Bool This function returns true if the regular expression matches an empty string. Note that the type does not include any constraints on the alphabet. Among other things, this means that it requires 'a' to be an instance of Eq. Some examples: matchEmpty (Sym 'a') = False matchEmpty (Rep (Sym 'a' :+: Sym 'b')) = True matchEmpty (Rep1 (Sym 'a' :|: Empty)) = True

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!