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 of m.

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 lists map.map , wrapping mulitmap using constructor mmap


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -