<div dir="ltr">You're very close. Take a look at the even clause: Let (k :: Integer), and consider how the type of the expression producing the error,<div><br></div><div>  Just (f2Maybe k)</div><div><br></div><div>differs from the type of the expression,</div><div><br></div><div><div><div>  (f2Maybe k)</div></div></div><div><br></div><div>Cheers,</div><div>Darren</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Oct 31, 2015 at 11:27 PM, Roelof Wobben <span dir="ltr"><<a href="mailto:r.wobben@home.nl" target="_blank">r.wobben@home.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    <div>Op 31-10-2015 om 12:10 schreef Roel van
      Dijk:<br>
    </div>
    <blockquote type="cite">
      <div dir="ltr">Small nitpick, but I would generally put the
        "exception" or "error" in the Left part of an Either and a
        correct result in the Right part. 
        <div><br>
        </div>
        <div>This has some advantages. </div>
        <div>1 - Right is right as opposed to wrong. Easy to remember
          mnemonic.</div>
        <div>2 - It fits neatly with the <font face="monospace,
            monospace">Monad (Either e)</font> instance.</div>
        <div><br>
        </div>
        <div>Roelof, a nice exercise is to first implement your<font face="monospace, monospace"> f2 </font>function with the <font face="monospace, monospace">Integer -> Maybe Integer</font>
          type and then with <font face="monospace, monospace">Integer
            -> Either String Integer</font>.</div>
        <div>If you realize that both <font face="monospace, monospace">Monad
            Maybe</font> and <font face="monospace, monospace">Monad
            (Either e)</font> you can use almost the same code.</div>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">2015-10-31 12:04 GMT+01:00 Darren Grant
          <span dir="ltr"><<a href="mailto:dedgrant@gmail.com" target="_blank">dedgrant@gmail.com</a>></span>:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <p dir="ltr">I'd expect most Haskellers to recommend
              something like,</p>
            <p dir="ltr">  f2 :: Integer -> Either Integer
              ErrorString</p>
            <p dir="ltr">where ErrorString is some specific error value
              type. (String may suffice for you.)</p>
            <p dir="ltr">This is a safe general solution, but there are
              many potentially more specific possibilities that might
              make your program simpler depending on how this function
              relates to the context it will be used in.</p>
            <p dir="ltr">Cheers,<br>
              Darren<br>
            </p>
            <div>
              <div>
                <div class="gmail_quote">On Oct 31, 2015 21:46, "Roelof
                  Wobben" <<a href="mailto:r.wobben@home.nl" target="_blank">r.wobben@home.nl</a>>
                  wrote:<br type="attribution">
                  <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Op
                    31-10-2015 om 11:40 schreef Darren Grant:<br>
                    <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
                      <br>
                      Unfrotunately the answer to this is not simple:<br>
                      <br>
                      <a href="http://stackoverflow.com/questions/4243117/how-to-catch-and-ignore-a-call-to-the-error-function" rel="noreferrer" target="_blank">http://stackoverflow.com/questions/4243117/how-to-catch-and-ignore-a-call-to-the-error-function</a><br>
                      <br>
                      'error' more or less terminates the program in an
                      unreasonable way.<br>
                      <br>
                      It would be preferable for f2 to result in a type
                      that can contain the error result to be parsed.<br>
                      <br>
                      Cheers,<br>
                      Darren<br>
                      <br>
                      <br>
                    </blockquote>
                    <br>
                  </blockquote>
                </div>
              </div>
            </div>
          </blockquote>
        </div>
      </div>
    </blockquote>
    <br>
    <br>
    Here my try for the Maybe <br>
    <br>
    <br>
    f2Maybe :: Integer -> Maybe Integer <br>
    f2Maybe n <br>
       | n > 0  = Nothing <br>
       | n == 0  = Just 1 <br>
       | even n = Just (f2Maybe ( n `div` 2) ^ 2)<br>
       | odd n  = Just ((f2Maybe ( n `div` 2) ^ 2) * 2) <br>
       <br>
    <br>
    But it will not compile , the clauses for even and odd do not work.
    <br>
    <br>
    Both maybe and either are not explained in the first 4 chapter of
    the Craft book. <br><span class="HOEnZb"><font color="#888888">
    <br>
    Roelof<br>
    <br>
  </font></span></div>

<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>