<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi edgar,<br>
the whole of my code and the input data are one contained world, I am
not using mondas - as I don't understand them properly, and they seem
not to be necessary for the simple algebra I am trying to develop. Do I
really need to use them here?<br>
<br>
Now, to your example:<br>
>>>Try for example in ghci: fromJust $ Just 1 >>= (\x
-> return $ x + 1)<br>
(I also had to search for definition of the $ operator, totally avoided
in the two books I have, and seems to be just syntactic sugar instead
of parentheses. Argh.)<br>
<br>
this seems to be equivalent to fromJust (Just 1), where I would assuem
a result of 1. But the example seems to be dependent on whatever x is
entered by keyboard. Am I right?<br>
<br>
Cheers<br>
Martin<br>
<br>
On 9/21/2010 3:19 PM, edgar klerks wrote:
<blockquote
cite="mid:AANLkTi=AGhpsn8UV-Hznk1_eR0+Sj5X_15ZWObhmDyvm@mail.gmail.com"
type="cite">Also note that Maybe is a monad. So you don't have to use
pattern matching. <br>
<br>
You have to import the Data.Maybe to get the functions in the scope. <br>
<br>
<div class="gmail_quote">On Tue, Sep 21, 2010 at 3:15 PM, edgar
klerks <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:edgar.klerks@gmail.com">edgar.klerks@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote"
style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello
Martin,<br>
<br>
You have two options. You can use fromJust :: Maybe a -> a, which is
a partial function, so it can fail if the supplied value is Nothing and
gives a hard to track down exception. <br>
<br>
Or you can use fromMaybe :: a -> Maybe a -> a, which returns a
default a in case Maybe a = Nothing and a if Maybe a = Just a. <br>
<br>
There is also a third: maybe :: b -> (a -> b) -> Maybe a ->
b, which can be useful in the last step of some chain of functions.
Note that fromMaybe is just (flip maybe id).<br>
<br>
Greets,<br>
<font color="#888888"><br>
Edgar <br>
</font>
<div>
<div class="h5"><br>
<div class="gmail_quote">On Tue, Sep 21, 2010 at 3:05 PM, Martin
Tomko <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:martin.tomko@geo.uzh.ch" target="_blank">martin.tomko@geo.uzh.ch</a>></span>
wrote:<br>
<blockquote class="gmail_quote"
style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Dear
All,<br>
as a newbie, I am only just discovering some intricacies of haskell.<br>
I have a Data.Map map, and am trying the lookup function to get the
value for a given key (it is a list in my case, btw). I am struggling
to get access to the value, as it is constructed using Just. I know
that the question is therefore more general then the application on
Map, so I would be glad to get a wider picture. I Checked in Real World
Haskell, btu did nto find and answer. In Haskell the craft of... I
found the following (p263):<br>
<br>
mapValue :: (a->b)-> Maybe a -> Maybe b<br>
mapValue g (Just a) = Just (g a)<br>
mapValue g Nothing = Nothing<br>
<br>
Which is fine, but it makes the Just constructor travel through the
whole code, which is annoying. Is there a way out? Or would that be a
dirty hack?<br>
<br>
I do not quite understand the following discussion of maybe (p263-4),
but it seems like the code suggested is able to return a value at the
end...<br>
<br>
Thanks<br>
Martin<br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a moz-do-not-send="true" href="mailto:Beginners@haskell.org"
target="_blank">Beginners@haskell.org</a><br>
<a moz-do-not-send="true"
href="http://www.haskell.org/mailman/listinfo/beginners"
target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</blockquote>
</div>
<br>
</div>
</div>
</blockquote>
</div>
<br>
</blockquote>
<br>
<br>
</body>
</html>