[Haskell-cafe] beginners question about fromMaybe
lrpalmer at gmail.com
Tue Jun 2 19:20:39 EDT 2009
On Tue, Jun 2, 2009 at 4:59 PM, Nico Rolle <nrolle at web.de> wrote:
> hi there
> heres a code snipped, don't care about the parameters.
> the thing is i make a lookup on my map "m" and then branch on that return
> probePhase is sc  m = 
> probePhase is sc (x:xs) m
> | val == Nothing = probePhase is sc xs m
> | otherwise = jr ++ probePhase is sc xs m
> jr = joinTuples sc x (fromMaybe  val)
> key = getPartialTuple is x
> val = Map.lookup key m
Here's my take. This ought to be equivalent, but I haven't tested.
probePhase is sc m = concatMap prefix
prefix x = let key = getPartialTuple is x in
maybe  (joinTuples sc x) $ Map.lookup key m
> the line "jr = joinTuples sc x (fromMaybe  val)" is kind of ugly
> because i know that it is not Nothing.
> is there a better way to solve this?
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe