I'm trying to use Data.Map to map strings to functions. The issue I'm having is that the main error handling in my program uses an Either monad, and Map.lookup
will return Maybe ([SomeVal] -> Either ValError SomeVal)
. How can I make Map.lookup
play nicely with the Either monad in this case?
apply :: String -> [SomeVal] -> Either ValError SomeVal
apply s args = (Map.lookup s prims) >>= \fn -> fn args
prims :: Map String ([SomeVal] -> Either ValError SomeVal)
prims = Map.fromList
[("key", function)
,("key2", function2)
]
::> apply "key" [val1, val2, val3]