Searching for Value Using Key in HashMap in Haskell

126 Views Asked by At

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?

1

There are 1 best solutions below

0
Souperman On BEST ANSWER

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"