type checking that I can't figure out ...

Hi Andrew (Bromage), I reversed the parameter order to Data.Map.lookup and calling fromJust to pull out value from Maybe wrapper ... all as you suggested:
remLookupFwd :: (ReVars m t) => SimplRe t -> ReM m t (ReInfo t) remLookupFwd re = do fwd <- gets resFwdMap let { Just reinfo = fromJust(M.lookup re fwd) } -- PROBLEM return reinfo
I am still getting a type mismatch: Swish\HaskellRDF\Dfa\Dfa.lhs:162:29: Couldn't match expected type `Maybe t' against inferred type `ReInfo t1' In the expression: fromJust (M.lookup re fwd) In a pattern binding: Just reinfo = fromJust (M.lookup re fwd) In the expression: do fwd <- gets resFwdMap let Just reinfo = fromJust (M.lookup re fwd) return reinfo Vasili

You've applied two solutions to get the value out -- pattern matching (Just reinfo) and fromJust. You should use one or the other, but not both: -- pattern matching remLookupFwd :: (ReVars m t) => SimplRe t -> ReM m t (ReInfo t) remLookupFwd re = do fwd <- gets resFwdMap let { Just reinfo = M.lookup re fwd } -- PROBLEM return reinfo -- fromJust remLookupFwd :: (ReVars m t) => SimplRe t -> ReM m t (ReInfo t) remLookupFwd re = do fwd <- gets resFwdMap let { reinfo = fromJust (M.lookup re fwd) } -- PROBLEM return reinfo BTW, I would personally write this as one line (untested) gets (fromJust . M.lookup re . resFwdMap) -Ross On Jun 3, 2009, at 1:18 PM, Vasili I. Galchin wrote:
Hi Andrew (Bromage),
I reversed the parameter order to Data.Map.lookup and calling fromJust to pull out value from Maybe wrapper ... all as you suggested:
remLookupFwd :: (ReVars m t) => SimplRe t -> ReM m t (ReInfo t) remLookupFwd re = do fwd <- gets resFwdMap let { Just reinfo = fromJust(M.lookup re fwd) } -- PROBLEM return reinfo
I am still getting a type mismatch:
Swish\HaskellRDF\Dfa\Dfa.lhs:162:29: Couldn't match expected type `Maybe t' against inferred type `ReInfo t1' In the expression: fromJust (M.lookup re fwd) In a pattern binding: Just reinfo = fromJust (M.lookup re fwd) In the expression: do fwd <- gets resFwdMap let Just reinfo = fromJust (M.lookup re fwd) return reinfo
Vasili _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Ross Mellgren schrieb:
You've applied two solutions to get the value out -- pattern matching (Just reinfo) and fromJust. You should use one or the other, but not both:
-- pattern matching remLookupFwd :: (ReVars m t) => SimplRe t -> ReM m t (ReInfo t) remLookupFwd re = do fwd <- gets resFwdMap let { Just reinfo = M.lookup re fwd } -- PROBLEM return reinfo
-- fromJust remLookupFwd :: (ReVars m t) => SimplRe t -> ReM m t (ReInfo t) remLookupFwd re = do fwd <- gets resFwdMap let { reinfo = fromJust (M.lookup re fwd) } -- PROBLEM return reinfo
BTW, I would personally write this as one line (untested)
gets (fromJust . M.lookup re . resFwdMap)
fromJust should be avoided, since it is partial and if it results in an error, the error message points to the implementation of fromJust, not its application. Pattern matching is better, but 'maybe' and 'fromMaybe' are best.

True, so perhaps better written as: import Data.Maybe (fromMaybe) gets (fromMaybe (error "could not find re in resFwdMap") . M.lookup re . resFwdMap) with more detail in error message as appropriate. -Ross On Jun 3, 2009, at 5:57 PM, Henning Thielemann wrote:
Ross Mellgren schrieb:
You've applied two solutions to get the value out -- pattern matching (Just reinfo) and fromJust. You should use one or the other, but not both:
-- pattern matching remLookupFwd :: (ReVars m t) => SimplRe t -> ReM m t (ReInfo t) remLookupFwd re = do fwd <- gets resFwdMap let { Just reinfo = M.lookup re fwd } -- PROBLEM return reinfo
-- fromJust remLookupFwd :: (ReVars m t) => SimplRe t -> ReM m t (ReInfo t) remLookupFwd re = do fwd <- gets resFwdMap let { reinfo = fromJust (M.lookup re fwd) } -- PROBLEM return reinfo
BTW, I would personally write this as one line (untested)
gets (fromJust . M.lookup re . resFwdMap)
fromJust should be avoided, since it is partial and if it results in an error, the error message points to the implementation of fromJust, not its application. Pattern matching is better, but 'maybe' and 'fromMaybe' are best.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Henning Thielemann
-
Ross Mellgren
-
Vasili I. Galchin