f# - Map and pattern matching -
i have assignment here i'm struggling with:
type multimap<'a,'b when 'a:comparison , 'b:comparison> = mmap of map<'a, list<'b>>
the assignment states
we define canonical representation of multimap representation elements in value-lists ordered. declare function
canonical: multimap<'a,'b> -> multimap<'a,'b> when 'a : comparison , 'b : comparison
canonical m
returns canonical representation ofm
.
right have:
let toorderedlist (mm:multimap<'a,'b>) = match mm | mmap m ->
i don't know how pattern match on this. help? :3
ok, give answer function looking can written this:
let cannonical (mmap m) = m |> map.map (fun _ vs -> list.sort vs) |> mmap
this deconstructs multimap
right in argument definition (pattern-matching) , pipes map<>
m
through - sorting list
s map.map
, wrapping mulitmap
using constructor mmap
Comments
Post a Comment