Map Patterns

We can also pattern match on Maps, and this is very similar to Records, except for some syntax changes. For example, getID let us get the ID of Wang from a map where we have to have at least Wang, Thomas and Leeming as keys.

  1. getID :: Map String Integer -> Maybe Integer
  2. getID #{ "Wang":= x, "Thomas" := y, "Leeming" := z } = Just x
  3. getID _ = Nothing
  4. > getID #{"Wang" => 10, "Thomas" => 20 , "Leeming" => 30 }
  5. {'Just',10}