Although Ganesh has answered your exact question, I want to say that your problem simply indicates an incorrect approach to design of datatypes.
The following approach is much more flexible and removes your problem as such:
data Person = Person { gender :: Gender, firstName :: String, lastName :: String }
data Gender = Male | Female
flipNames (Person gender firstName lastName) = Person gender lastName firstName
The rule behind this is pretty simple: whenever you see yourself creating multiple constructors with the same fields, just use a single constructor and introduce another field with an enum type, as in the code above.
You won't lose any pattern matching capabilities, as the patterns can be like Person Male firstName lastName
, and you'll be able to make the Gender
type derive Enum
and Bounded
which will surely help you with types which aren't as trivial. E.g.:
data Gender = Male | Female deriving (Enum, Bounded)
allGenders :: [Gender]
allGenders = enumFrom minBound
maidenName :: Person -> Maybe String
maidenName (Person Female _ z) = Just z
maidenName _ = Nothing