The following example in the documentation fails to compile. The error message is The typePersonhas 3 fields but the pattern expects 1 fields.
personinfo(person) = @match person begin
Person("Julia", lname, _) => "Found Julia $lname"
Person(fname, "Julia", _) => "$fname Julia was here!"
Person(fname, lname,
Address(_, "Cambridge", zip)) => "$fname $lname lives in zip $zip"
Person(_...) => "Unknown person!" # this line fails
The following change corrects the problem:
personinfo(person) = @match person begin
Person("Julia", lname, _) => "Found Julia $lname"
Person(fname, "Julia", _) => "$fname Julia was here!"
Person(fname, lname,
Address(_, "Cambridge", zip)) => "$fname $lname lives in zip $zip"
Person(_, _, _) => "Unknown person!"
end
or
personinfo(person::Person) = @match person begin
Person("Julia", lname, _) => "Found Julia $lname"
Person(fname, "Julia", _) => "$fname Julia was here!"
Person(fname, lname,
Address(_, "Cambridge", zip)) => "$fname $lname lives in zip $zip"
_ => "Unknown person!"
end
The following example in the documentation fails to compile. The error message is
The type
Personhas 3 fields but the pattern expects 1 fields.
The following change corrects the problem:
or