<div dir="ltr">The meaning of "pure", and the meaning of "effect" are closely intertwined, because essentially, "pure" (in this usage) means "not having any effects", and "effect" means "the part of the function result that isn't pure". If what you have in your mind is a function `div :: Int -> Int -> Int`, and instead have to settle for `div :: Int -> Int -> Maybe Int`, they you could consider the first the type it should have "if it were pure", and call the Maybe type "an effect". The words are relative to your starting assumption of what type div should have, though. As you mention, you could also quite reasonably admit that `Maybe Int` is a perfectly good type on its own, and consider `safeDiv` to be a pure function with this type as a codomain.<div><br></div><div>You can even pull the same trick with more powerful effects. The type `IO Int` is a (more or less) defined type, and its values are ACTIONS that your computer could take, which if they don't fail return an Int. From this perspective, even a function like `readFile :: FilePath -> IO ByteString` is a "pure" function, which maps file paths to actions. But if you consider it as a map from file paths to bytestrings, then it is effectful. Again, these words are defined relative to what you consider the result to be. (I'm ignoring, here, some questions about what the correct semantics for IO types even is...)</div><div><br></div><div>If you want a more formal (but less intuitive) way to think about this, then you can turn to category theory. In category theory, a monad (say, F) is an endofunctor in some category -- for us, typically the category of Haskell types and functions. But F also defines a SECOND category, called the Kleisli category of F: the set of types here the same, but a "Kleisli arrow" between two objects A and B is a function A -> F B in the base category. Notice that any Kleisli arrow IS an arrow in the base category, so in that sense you could claim that it's "pure". But IF you choose to think about it as an arrow from A to B, THEN you must be talking about the Kleisli category, and it has an effect captured by F. If that wasn't what you were looking for, though, feel free to ignore it.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 30, 2017 at 7:11 PM, Steven Leiva <span dir="ltr"><<a href="mailto:leiva.steven@gmail.com" target="_blank">leiva.steven@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <u></u> <div style="word-wrap:normal;word-break:break-word"> <table class="m_1174947246105082016container" lang="container" dir="ltr" border="0" cellpadding="0" cellspacing="0" valign="top" style="width:100%;margin-top:6px"> <tbody><tr> <td valign="top" class="m_1174947246105082016message-wrapper" style="line-height:1.31;color:#222;font-family:arial,sans-serif"> <div>Hello Again Brandon,</div><div><br></div><div>Thank you for the explanation. I'll have to mull it over a bit to let it sink in. I am finding the overloading of purity to be easier to grasp than the meaning of effect. I think the reason for that is precisely because it depends on the context (generally speaking) in which it is being used. For example, in the case of Maybe, the effect is possible failure. In the case of lists, the effect is non-determinism, etc. </div><img align="left" width="0" height="0" style="border:0;width:0px;height:0px" src="https://track.mixmax.com/api/track/v2/Ofb5aa8VB4bGdcYUR/i02bj5CbpFWbnBkblZXZ0NnLhZXalxmI/IyZy9mLsxWZrNXYoBUZmF2YtwGblt2chhmI/ISZmF2YtwGblt2chhmI?sc=false" alt=""> </td> </tr> </tbody></table><div><div class="h5"> <div> <div> <p><br></p> <div class="gmail_extra"> <p><br></p> <div class="gmail_quote"> On Mon, Oct 30, 2017 10:02 PM, Brandon Allbery <span dir="ltr"> <a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a></span> wrote:<br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <u></u> <div dir="ltr">In this specific case it is actually pure, because Maybe is pure, but in the general case it behaves with respect to Applicative (and Monad, which this appears to be leading up to) as effectful. In this context, an effect is just whatever behavior is captured by the Applicative/Monad.<div><br></div><div>"purity" is a bit overloaded:</div><div><br></div><div>- purity with respect to an effect of some unspecified kind, as here;</div><div><br></div><div>- purity with respect to IO which encapsulates behavior not contained specifically within your program, the most common meaning in Haskell;</div><div><br></div><div>- purity with respect to cross-thread effects in IO/STM;</div><div><br></div><div>- purity with respect to mutability in ST;</div><div><br></div><div>....</div><div><br></div></div><div><br><div>On Mon, Oct 30, 2017 at 9:49 PM, Steven Leiva <span dir="ltr"><<a href="mailto:leiva.steven@gmail.com" target="_blank">leiva.steven@gmail.com</a>></span> wrote:<br><blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <u></u> <div style="word-wrap:normal;word-break:break-word"> <table lang="container" dir="ltr" border="0" cellpadding="0" cellspacing="0" valign="top" style="width:100%;margin-top:6px"> <tbody><tr> <td valign="top" style="line-height:1.31;color:#222;font-family:arial,sans-serif"> <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> <table id="m_1174947246105082016m_-1538506955436073332" cellpadding="0" cellspacing="0" style="border:1px solid #f5ffff;border-radius:4px;width:100%;max-width:578px"> <tbody><tr style="border:1px solid #d5ecff;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"> <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"> <div 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%" 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;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> <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> <table id="m_1174947246105082016m_-1538506955436073332" cellpadding="0" cellspacing="0" style="border:1px solid #f5ffff;border-radius:4px;width:100%;max-width:578px"> <tbody><tr style="border:1px solid #d5ecff;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"> <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"> <div 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%" 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;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> <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><span><font color="#888888"><div><br></div><div>Steven Leiva<br><span><span id="m_1174947246105082016m_-1538506955436073332gc-number-0" title="Call with Google Voice"><a href="tel:(305)%20528-6038" value="+13055286038" target="_blank">305.528.6038</a></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/ste<wbr>venleiva</a><br></div><img align="left" width="0" height="0" style="border:0;width:0px;height:0px" src="https://compose.mixmax.com/img/blank.png" alt=""> </font></span></td> </tr> </tbody></table> </div> <br>______________________________<wbr>_________________<br> Haskell-Cafe mailing list<br> To (un)subscribe, modify options or view archives go to:<br> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bi<wbr>n/mailman/listinfo/haskell-caf<wbr>e</a><br> Only members subscribed via the mailman list are allowed to post.<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div data-smartmail="gmail_signature"><div dir="ltr"><div>brandon s allbery kf8nh sine nomine associates</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a> <a href="mailto:ballbery@sinenomine.net" target="_blank">ballbery@sinenomine.net</a></div><div>unix, openafs, kerberos, infrastructure, xmonad <a href="http://sinenomine.net" target="_blank">http://sinenomine.net</a></div></div></div> </div> </blockquote> </div> </div> </div> </div> <br><br>Steven Leiva<br><a href="tel:(305)%20528-6038" value="+13055286038" target="_blank">305.528.6038</a><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/<wbr>stevenleiva</a><br> </div></div></div> <br>______________________________<wbr>_________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/haskell-<wbr>cafe</a><br>
Only members subscribed via the mailman list are allowed to post.<br></blockquote></div><br></div>