Porting Haskell code to a new version of Data.Map.lookup

I have to compile in a recent version of Haskell software written for a previous version of the standard libraries. The code assumes the Data.Map.lookuptype:

lookup :: (Monad m, Ord k) => k -> Map k a -> m a

as was the case with, for example, GHC 6.8.1 / containers 0.1.0.0. But since (at least) GHC 6.10.1 / containers 0.2.0.0 Data.Map.lookupis of type:

lookup :: Ord k => k -> Map k a -> Maybe a

Since I know little about Haskell, I am looking for a workaround or equivalent function in current libraries. Can anybody help me?

+3
source share
1 answer

Just find out what the old one lookupdid in every possible case and replicated the functionality.

, ? , fail ?

lookup2 el map =
  case lookup el map of
    Just x -> return x
    Nothing -> fail "Element doesn't exist in the map"
+5

Source: https://habr.com/ru/post/1765288/


All Articles