
22 Dec
2011
22 Dec
'11
2:44 p.m.
Is there a more elegant way to write 'test' in the following? import qualified Data.Map as M import Data.Map(Map) import Control.Monad.Error testMap :: Map Int String testMap = M.fromList [(1, "whatever"), (2, "dude")] test :: Int -> Either String String test x = do y <- case M.lookup x testMap of Nothing -> throwError "not in map" Just z -> return z return y