haskell - Get tuple from list and use it as Map key -
i'm haskell newbie , i'm trying use map.fromlist. have defined following data types:
type no = string data arco = arco { de :: no , para :: no , custo :: float } deriving (show, ord, eq) i have list of arco , want map them, using (de, para) tuple key, , custo value. how can achieve that?
thanks
i think achieve using folding functions or list mapping first convert list of arco values simple list, , using map.fromlist build map list of key/value pairs. along lines of (not tested):
map.fromlist (foldr (\x res -> ((de x, para x), custo x):res) [] yourarcolist) or map:
map.fromlist $ map (\x -> ((de x, para x), custo x)) yourarcolist or list comprehension:
[((de x, para x), custo x) | x <- yourarcolist] de, para, , cusot functions automatically created haskell can extract field values type values.
Comments
Post a Comment