Home > Software design >  Searching for Value Using Key in HashMap in Haskell
Searching for Value Using Key in HashMap in Haskell

Time:01-19

I am trying to create a simple program which converts any given char number 1-9 to its roman equivalent. I figured I could store the value pairs in a map (ex. [('1', "I"), ('2', "II"), ...]

Given this, how do I look through a map in Haskell?

CodePudding user response:

If you have an association list you can use the lookup function from Prelude to get a value out of the list. For example

list :: [(Char, String)]
list = [('1', "I"), ('2', "II")]

val = lookup '1' list -- Just "I"
  • Related