<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"> <head> <meta name="viewport" content="width=device-width,initial-scale=1"> <!--[if gte mso 9]>
    <xml>
      <o:OfficeDocumentSettings>
        <o:AllowPNG/>
        <o:PixelsPerInch>96</o:PixelsPerInch>
     </o:OfficeDocumentSettings>
    </xml>
    <![endif]--> <style type="text/css">* a:hover{cursor:pointer;}</style> <style>body {-webkit-animation:bugfix infinite 1s;}@-webkit-keyframes bugfix {from {position:relative;}to {position:relative;}}</style> </head> <body style="word-wrap:normal;word-break:break-word"> <style>a {word-wrap:normal;word-break:break-word;}.background-contain {background-size:contain;}@media only screen and (max-width:600px) {.container {-webkit-text-size-adjust:none !important;}.container,.palm-one-whole {width:100% !important;min-width:100% !important;}.palm-one-half {width:50% !important;min-width:50% !important;box-sizing:border-box;}blockquote .container,blockquote .container div,blockquote .container table {width:auto !important;min-width:0 !important;position:relative !important;}img {max-width:100%;}.border-outer,.border-middle,.border-inner,.inner,[title="separator"] {width:100% !important;}.innercell {padding:8px !important;}.palm-block {display:block !important;}td.palm-one-whole {display:inline-block !important;padding:0;}td.palm-one-whole:first-child:not(:only-child) {margin-bottom:16px;}td.hostname {padding-top:3px !important;}}@media only screen and (min-width:601px) {.preview-card {max-width:600px !important;}}@media only screen and (min-device-width :320px) and (max-device-width :568px),only screen and (min-device-width :768px) and (max-device-width :1024px),only screen and (max-device-width:640px),only screen and (max-device-width:667px),only screen and (max-width:480px){.container {width:100% !important;min-width:100% !important;}.p,.small,li,font[size="2"],font[size="3"] {font-size:1em !important;}}@media only screen and (min-device-width :320px) and (max-device-width :568px),only screen and (min-device-width :768px) and (max-device-width :1024px),only screen and (min-device-width :1224px)  {.message-wrapper {padding-top:6px;}.apple-only[style] {display:block !important;max-height:none !important;line-height:normal !important;overflow:visible !important;height:auto !important;width:100% !important;position:relative !important;}.no-apple {display:none !important;}form {font-size:inherit;}input[type="text"] {height:43px;padding-left:4px !important;}button:hover {cursor:pointer;}}@media only screen and (min-device-width :1224px)  {.apple-mail-form {display:block !important;background-color:white !important;}}* [office365] .outlook-com-hidden {display:none !important;}* [office365] .outlook-com-button {display:block;}* [office365] .outlook-com-only {display:block !important;max-height:none !important;line-height:normal !important;overflow:visible !important;height:auto !important;width:100% !important;position:relative !important;}.ExternalClass {width:100%;}.ExternalClass .outlook-com-button {display:block;}.ExternalClass button {height:auto;}.ExternalClass .outlook-com-hidden {display:none !important;}.ExternalClass .outlook-com-only {display:block !important;max-height:none !important;line-height:normal !important;overflow:visible !important;height:auto !important;width:100% !important;position:relative !important;}.ExternalClass .ecxlabels {display:none !important;}.ExternalClass .ecxlabels {display:none !important;}.ExternalClass .ecxarrow {display:none !important;}.ExternalClass cite >div + div {padding:0 0 4px 0;}.ExternalClass .h1 {padding-bottom:5px;}.ExternalClass .h2 {padding-bottom:5px;}.ExternalClass .h3 {padding-bottom:5px;}.ExternalClass [lang="brand-pinterest"] {width:280px !important;}</style> <!--[if (gte mso 9)|(IE)]>
    
    <style>
      a, body {
        font-family: 'Calibri', Arial, sans-serif;
      }
    
      img {
        border: none !important;
        -ms-interpolation-mode:bicubic;
      }
    
      td {
        mso-line-height-rule:exactly !important;
      }
    
      .mso-card-inner table {
        border-collapse: collapse !important;
        mso-table-lspace:0pt;
        mso-table-rspace:0pt;
        vertical-align: top;
      }
    
      .outlook-com-only {
        display: none !important;
        font-size: 0 !important;
      }
    
      #mso-one-whole {
        width: 100% !important;
      }
    
    
    
        .border-outer,
        .border-middle,
        .border-inner {
          border: none !important;
        }
    
        .border-middle,
        .border-inner {
          width: 100% !important;
        }
    
        .mso-border-outer,
        .mso-border-middle,
        .mso-border-inner {
          padding: 1px;
        }
    
        .mso-border-outer { background-color: rgb(245, 255, 255); }
        .mso-border-middle { background-color: rgb(223, 246, 255); }
        .mso-border-inner { background-color: rgb(153, 176, 225); }
    
    </style>
    
    <![endif]--> <table class="container" lang="container" dir="ltr" border="0" cellpadding="0" cellspacing="0" valign="top" style="width:100%;margin-top:6px"> <tr> <td valign="top" class="message-wrapper" style="line-height:1.31;color:#222;font-family:arial,sans-serif"> <!--[if mso]><table  border="0" cellpadding="0" cellspacing="0" valign="top" style="border-collapse:separate;"><tr><td valign="top"><![endif]--> <div>Hi Everyone, </div><div><br></div><div>I am reading the 2nd edition of Graham Hutton's Programming in Haskell. I'm not reading the entire book, just the parts of Haskell that I am still iffy on.</div><div><br></div><div>Anyway, in Chapter 12, Section 3, Hutton introduces monads. </div><div><br></div><div>He start off with the following code:</div><div> <div style="height:4px;font-size:4px"><br></div> <!--[if mso]>
<table class="mso-card-v3" width="578" cellpadding="0" cellspacing="0" style="border:1px solid #f5ffff">
  <tr>
    <td style="border:1px solid #d5ecff; background-color:#99b0e1; padding:1px;">
<![endif]--> <table id="" class="card-v3" cellpadding="0" cellspacing="0" style="border:1px solid #f5ffff;border-radius:4px;width:100%;max-width:578px;mso-border-alt:none"> <tbody><tr style="border:1px solid #d5ecff;mso-border-alt:none;display:block;border-radius:3px"> <td style="display:block;padding:8px;border-radius:2px;border:1px solid #99b0e1;font-size:0;vertical-align:top;background-color:white;mso-border-alt:none;position:relative"> <table cellpadding="0" cellspacing="0" valign="top" width="100%" style="border-collapse:collapse;width:100% !important"> <tbody><tr> <td valign="top" align="left" width="100%" style="min-width:100% !important;padding-top:6px;padding-bottom:8px;line-height:18px;font-weight:400;font-size:13px;font-family:'proxima-nova','Avenir Next','Segoe UI','Calibri','Helvetica Neue',Helvetica,Arial,sans-serif"> first </td> </tr> </tbody></table> <div style="color:#333;font-size:16px;border-radius:3px"> <div style="margin-bottom:1em;font-family:Consolas,Liberation Mono,Menlo,Courier,monospace;border:1px solid #ddd;border-radius:3px;overflow:hidden;-webkit-mask-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAA5JREFUeNpiYGBgAAgwAAAEAAGbA+oJAAAAAElFTkSuQmCC)"> <div class="code-snippet-container" style="width:540px;overflow-x:scroll"> <div style="font-size:12px;line-height:1.4"> <table cellpadding="0" cellspacing="0" width="1000" style="width:1000px !important;font-family:Consolas,Liberation Mono,Menlo,Courier,monospace;font-size:12px;font-weight:normal;line-height:1.4;margin:0;padding:0;color:#333;background:rgb(255,255,255)"> <tbody><tr> <td align="left" style="padding:.5em 1em"> <pre style="white-space:pre!important;font-family:Consolas,Liberation Mono,Menlo,Courier,monospace;padding:0;margin:0;font-size:100%;line-height:inherit;background:transparent;border:0;background:rgb(255,255,255)">                  <div style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px"><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)">module</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)"> </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">Expr</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)"> </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)">where</span></div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px"></div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px"><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)">data</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(102,105,105)">Expr</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(62,153,159)">=</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(102,105,105)">Val</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(102,105,105)">Int</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(62,153,159)">|</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(102,105,105)">Div</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(102,105,105)">Expr</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(102,105,105)">Expr</span></div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px"></div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px"><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(66,113,174)">eval</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)"> </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)">::</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)"> </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)">Expr</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)"> </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)">-></span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)"> </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(201,158,0)">Int</span></div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px">eval (<span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(102,105,105)">Val</span> n) <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(62,153,159)">=</span> n</div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px">eval (<span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(102,105,105)">Div</span> el er) <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(62,153,159)">=</span> eval el <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">`</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(62,153,159)">div</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">`</span> eval er</div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px"></div></div>
                </pre> </td> </tr> </tbody></table> </div> </div> </div> </div> <table width="100%" class="badge-mixmax" cellpadding="0" cellspacing="0" valign="top" style="min-width:100% !important;border-collapse:collapse;border-top:1px solid #dde;table-layout:fixed"> <tbody><tr> <td valign="top" style="padding-top:8px;font-size:0px;text-align:left"> <a href="https://mixmax.com/r/59ec918e83319a2a077ff18c" style="display:inline-block;vertical-align:top;font-size:0" target="_blank"> <img src="https://emailapps.mixmax.com/img/badge_mixmax.png" align="top" height="20" style="display:block" alt="Mixmax" border="0"> </a> <a style="color:#aab;vertical-align:top;mso-line-height-rule:exactly;padding-top:4px;display:inline-block;font-size:11px;line-height:16px;margin:0;letter-spacing:1px;padding-left:6px;text-align:left;text-decoration:none;text-transform:uppercase;font-family:'Avenir Next','Segoe UI','Calibri',Arial,sans-serif" href="https://mixmax.com/r/59ec918e83319a2a077ff18c" target="_blank">Not using Mixmax yet?</a> </td> </tr> </tbody></table> </td> </tr> </tbody></table> <!--[if mso]>
    </td>
  </tr>
</table>
<![endif]--> <div style="height:4px;font-size:4px"><br></div> </div><div><br></div><div>And then he points out that the second clause of <b>eval</b> will raise an error if <b>eval er</b> evaluates to 0. </div><div><br></div><div>One solution is that, instead of using the <b>div</b> function, we use a <b>safeDiv</b> <b>:: Int -> Int -> Maybe Int</b> function, which evaluate to <b>Nothing</b> if the divisor is 0. This means that <b>expr</b>'s type changes from <b>eval :: Eval -> Int</b> to <b>eval :: Eval -> Maybe Int</b>, and this means that implementing <b>eval</b> becomes very verbose:</div><div><br></div><div> <div style="height:4px;font-size:4px"><br></div> <!--[if mso]>
<table class="mso-card-v3" width="578" cellpadding="0" cellspacing="0" style="border:1px solid #f5ffff">
  <tr>
    <td style="border:1px solid #d5ecff; background-color:#99b0e1; padding:1px;">
<![endif]--> <table id="" class="card-v3" cellpadding="0" cellspacing="0" style="border:1px solid #f5ffff;border-radius:4px;width:100%;max-width:578px;mso-border-alt:none"> <tbody><tr style="border:1px solid #d5ecff;mso-border-alt:none;display:block;border-radius:3px"> <td style="display:block;padding:8px;border-radius:2px;border:1px solid #99b0e1;font-size:0;vertical-align:top;background-color:white;mso-border-alt:none;position:relative"> <table cellpadding="0" cellspacing="0" valign="top" width="100%" style="border-collapse:collapse;width:100% !important"> <tbody><tr> <td valign="top" align="left" width="100%" style="min-width:100% !important;padding-top:6px;padding-bottom:8px;line-height:18px;font-weight:400;font-size:13px;font-family:'proxima-nova','Avenir Next','Segoe UI','Calibri','Helvetica Neue',Helvetica,Arial,sans-serif"> second </td> </tr> </tbody></table> <div style="color:#333;font-size:16px;border-radius:3px"> <div style="margin-bottom:1em;font-family:Consolas,Liberation Mono,Menlo,Courier,monospace;border:1px solid #ddd;border-radius:3px;overflow:hidden;-webkit-mask-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAA5JREFUeNpiYGBgAAgwAAAEAAGbA+oJAAAAAElFTkSuQmCC)"> <div class="code-snippet-container" style="width:540px;overflow-x:scroll"> <div style="font-size:12px;line-height:1.4"> <table cellpadding="0" cellspacing="0" width="1000" style="width:1000px !important;font-family:Consolas,Liberation Mono,Menlo,Courier,monospace;font-size:12px;font-weight:normal;line-height:1.4;margin:0;padding:0;color:#333;background:rgb(255,255,255)"> <tbody><tr> <td align="left" style="padding:.5em 1em"> <pre style="white-space:pre!important;font-family:Consolas,Liberation Mono,Menlo,Courier,monospace;padding:0;margin:0;font-size:100%;line-height:inherit;background:transparent;border:0;background:rgb(255,255,255)">                  <div style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)"><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px"><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)">module</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)"> </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">Expr</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)"> </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)">where</span></div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px"></div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px"><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)">data</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(102,105,105)">Expr</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(62,153,159)">=</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(102,105,105)">Val</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(102,105,105)">Int</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(62,153,159)">|</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(102,105,105)">Div</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(102,105,105)">Expr</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(102,105,105)">Expr</span></div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px"></div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px"><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(66,113,174)">eval</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)"> </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)">::</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)"> </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)">Expr</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)"> </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)">-></span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)"> </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(201,158,0)">Maybe</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)"> </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(201,158,0)">Int</span></div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px">eval (<span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(102,105,105)">Val</span> n) <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(62,153,159)">=</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(245,135,31)">Just</span> n</div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px">eval (<span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(102,105,105)">Div</span> el er) <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(62,153,159)">=</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)">case</span> eval el <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)">of</span></div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px"><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span>    <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(245,135,31)">Nothing</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(62,153,159)">-></span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(245,135,31)">Nothing</span></div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px"><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span>    <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(245,135,31)">Just</span> y <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(62,153,159)">-></span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)">case</span> eval er <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)">of</span></div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px"><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span>    <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(245,135,31)">Nothing</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(62,153,159)">-></span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(245,135,31)">Nothing</span></div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px"><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">    </span>    <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(245,135,31)">Just</span> x <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(62,153,159)">-></span> y <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">`</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(62,153,159)">safeDiv</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">`</span> x</div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px"></div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px"><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(66,113,174)">safeDiv</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)"> </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)">::</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)"> </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(201,158,0)">Int</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)"> </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)">-></span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)"> </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(201,158,0)">Int</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)"> </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)">-></span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)"> </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(201,158,0)">Maybe</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(137,89,168)"> </span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(201,158,0)">Int</span></div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px">safeDiv x y</div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px">    <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(62,153,159)">|</span> y <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(62,153,159)">==</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(245,135,31)">0</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(62,153,159)">=</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(245,135,31)">Nothing</span></div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px">    <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(62,153,159)">|</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(66,113,174)">otherwise</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(62,153,159)">=</span> <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(245,135,31)">Just</span> (x <span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">`</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(62,153,159)">div</span><span style="font:normal normal normal normal 12px / normal Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76)">`</span> y)</div><div style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:Monaco,Menlo,"Ubuntu Mono",Consolas,source-code-pro,monospace;color:rgb(77,77,76);height:16px"></div></div>
                </pre> </td> </tr> </tbody></table> </div> </div> </div> </div> <table width="100%" class="badge-mixmax" cellpadding="0" cellspacing="0" valign="top" style="min-width:100% !important;border-collapse:collapse;border-top:1px solid #dde;table-layout:fixed"> <tbody><tr> <td valign="top" style="padding-top:8px;font-size:0px;text-align:left"> <a href="https://mixmax.com/r/59ec918e83319a2a077ff18c" style="display:inline-block;vertical-align:top;font-size:0" target="_blank"> <img src="https://emailapps.mixmax.com/img/badge_mixmax.png" align="top" height="20" style="display:block" alt="Mixmax" border="0"> </a> <a style="color:#aab;vertical-align:top;mso-line-height-rule:exactly;padding-top:4px;display:inline-block;font-size:11px;line-height:16px;margin:0;letter-spacing:1px;padding-left:6px;text-align:left;text-decoration:none;text-transform:uppercase;font-family:'Avenir Next','Segoe UI','Calibri',Arial,sans-serif" href="https://mixmax.com/r/59ec918e83319a2a077ff18c" target="_blank">Not using Mixmax yet?</a> </td> </tr> </tbody></table> </td> </tr> </tbody></table> <!--[if mso]>
    </td>
  </tr>
</table>
<![endif]--> <div style="height:4px;font-size:4px"><br></div> </div><div><br></div><div>In order to make <b>eval</b> more concise, we can try the applicative style, where the second clause of the <b>eval</b> function becomes <b>pure safeDiv <*> eval el <*> eval er</b>. Of course, that doesn't work because <b>pure safeDiv</b> has the type <b>Int -> Int -> Maybe Int</b>, and what we need is a function of type <b>Int -> Int -> Int</b>. </div><div><br></div><div>Anyways, this is all setup / context to what Hutton says next:</div><div><br></div><div><i>The conclusion is that the function eval does not fit the pattern of effectful programming that is capture by applicative functors. The applicative style restricts us to applying pure functions to effectful arguments: eval does not fit this pattern because the function safeDiv that is used to process the resulting values is not a pure function, but may itself fail<b>. </b></i></div><div><br></div><div>I am confused by Hutton's use of the word effectful and by his description of safeDiv as "not a pure function". I tried skimming the other sections of the book to see if he provided a definition of this somewhere, but if he did, I couldn't find it. So my question is, in what way does Hutton mean for the reader to understand the words effect / effectful, and why does he describe the function safeDiv as not a pure function? </div><div><br></div><div>Thank you!</div><div><br></div><div class="mixmax_signature">Steven Leiva<br><span><span id="gc-number-0" class="gc-cs-link" title="Call with Google Voice">305.528.6038</span></span><br><a href="mailto:leiva.steven@gmail.com" target="_blank">leiva.steven@gmail.com</a><br><a href="http://www.linkedin.com/in/stevenleiva" target="_blank">http://www.linkedin.com/in/stevenleiva</a><br></div><img align="left" width="0" height="0" style="border:0;width:0px;height:0px" src="https://track.mixmax.com/api/track/v2/xGT2LRgoSfUNTPXG4/i02bj5CbpFWbnBkblZXZ0NnLhZXalxmI/IyZy9mLsxWZrNXYoBUZmF2YtwGblt2chhmI/ISZmF2YtwGblt2chhmI?sc=false" alt=""> <!--[if mso]></td></tr></table><![endif]--> </td> </tr> </table> </body> </html>