An example of using Data.Map in Haskell

Viewed 39249

I'm new in Haskell and I need to define an empty Data.map and assigning a "list of integers" (e.g. [1,2,3]) to its keys by using insert function and also updating the values. Then looking up the key values.

What I have tried so far is :

import qualified Data.Map

foo num =
    let
        my_map  = Data.Map.empty

        new_map = bar my_map  num 1

    in
        Data.Map.lookup 1 new_map


bar my_map num c =
    if c > num then my_map
    else
        Data.Map.insert  c  [c] my_map
        bar my_map  num  c+1

This code doesn't work.

Could you have a simple example please?

4 Answers
Related