Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maps and sets #13

Open
chris-martin opened this issue Sep 30, 2019 · 1 comment
Open

Maps and sets #13

chris-martin opened this issue Sep 30, 2019 · 1 comment
Labels
good for new contributors Pull requests welcome! new example This issue is about writing a new example program.

Comments

@chris-martin
Copy link
Member

As a jumping-off point for an example involving the Map type from containers here is a fairly direct translation from Go By Example:

import qualified Data.Map as Map

main =
  do
    let m = Map.fromList [("k1", 7), ("k2", 13)]
    putStrLn ("map: " ++ show m)
    putStrLn ("v1: " ++ show (Map.lookup "k1" m))
    putStrLn ("size: " ++ show (Map.size m))

    let m' = Map.delete "k2" m
    putStrLn ("map: " ++ show m')
    putStrLn ("v2: " ++ show (Map.lookup "k2" m'))
$ runhaskell maps.hs
map: fromList [("k1",7),("k2",13)]
v1: Just 7
size: 2
map: fromList [("k1",7)]
v2: Nothing

Since Set is closely related to Map, it might be nice to discuss sets at the same time.

We might also want to show using a custom datatype as the key in a map, to demonstrate how you need to derive Eq and Ord.

@chris-martin chris-martin added good for new contributors Pull requests welcome! new example This issue is about writing a new example program. labels Sep 30, 2019
@Benjmhart
Copy link

I'd be happy to write an example sometime this week

beyond demonstrating what happens if you try to use a type without Eq or Ord, - do you have any other goals for this section?

should we discuss time-space complexity? compare Map with, say IntMap? what knowledge would you like someone to take away from this section?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good for new contributors Pull requests welcome! new example This issue is about writing a new example program.
Projects
None yet
Development

No branches or pull requests

2 participants