Map Patterns
We can also pattern match on Map
s, and this is very similar to Record
s, 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.
getID :: Map String Integer -> Maybe Integer
getID #{ "Wang":= x, "Thomas" := y, "Leeming" := z } = Just x
getID _ = Nothing
> getID #{"Wang" => 10, "Thomas" => 20 , "Leeming" => 30 }
{'Just',10}
当前内容版权归 hamler-lang 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 hamler-lang .