23 Dec
2011
23 Dec
'11
1:14 a.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