Search code examples
haskellhashmaproman-numerals

Searching for Value Using Key in HashMap in Haskell


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?


Solution

  • 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"