<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Paul Graham refers to all those features as "orthogonality" ("On Lisp", pg. 63) and you're right, Haskell has it in spades, but it takes time to understand all of it and even more time to use it effectively. One almost needs a checklist.<br><br>But I think I'm catching on. I programmed this craps simulation last week. It's a problem from "Problems For Computer Solution", Gruenberger &amp; Jaffray, 1965, The RAND Corp.<br><br><span style="font-family: courier,monaco,monospace,sans-serif;">import Control.Monad.State</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">import System.Random</span><br style="font-family: courier,monaco,monospace,sans-serif;"><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">type
 GeneratorState = State StdGen</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">data Craps a = Roll a | Win a | Lose a deriving (Show)</span><br style="font-family: courier,monaco,monospace,sans-serif;"><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">f :: Craps [Int] -&gt; GeneratorState (Craps [Int])</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">f (Roll []) = do g0 &lt;- get</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let (d1,g1) = randomR (1,6) g0</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span
 style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (d2,g2) = randomR (1,6) g1</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t1 = d1+d2</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; put g2</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case t1 of</span><br
 style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2 -&gt; return (Lose [t1])</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 -&gt; return (Lose [t1])</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7 -&gt; return (Win [t1])</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family:
 courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 11 -&gt; return (Win [t1])</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _ -&gt; do g2 &lt;- get</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let (d3,g3) = randomR (1,6) g2</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family:
 courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (d4,g4) = randomR (1,6) g3</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t2 = d3+d4</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; put g4</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span
 style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if t2 == t1</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; then do</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (Win [t1,t2])</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span
 style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if t2 == 7</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; then do</span><br style="font-family:
 courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (Lose [t1,t2])</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family:
 courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f (Roll [t2,t1])</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">f (Roll l) = do g0 &lt;- get</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let (d1,g1) = randomR (1,6) g0</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (d2,g2) = randomR (1,6) g1</span><br
 style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t = d1+d2</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if t == (last l)</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; then do</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family:
 courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; put g2</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (Win (reverse (t:l)))</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if t == 7</span><br style="font-family:
 courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; then do</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; put g2</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (Lose (reverse (t:l)))</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family:
 courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else do</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; put g2</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f (Roll (t:l)) </span><br style="font-family: courier,monaco,monospace,sans-serif;"><br><span style="font-family: courier,monaco,monospace,sans-serif;">progressive (z@(x:xs),n) (Win _) = let b = x + (last
 xs)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; in (init xs,n+b) <br>progressive (z@(x:xs),n) (Lose _) = let b = x + (last xs)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; in (z ++ [b],n-b)<br></span><br><span style="font-family: courier,monaco,monospace,sans-serif;">*Main&gt; let r = evalState (sequence $ replicate 6 (f (Roll []))) (mkStdGen 987)</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">*Main&gt; r</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">[Win
 [8,12,10,3,8],Win [5,9,10,11,12,11,8,9,5],Win [7],Lose [9,7],Win [5,5],Win [5,2,6,4,6,8,5]]</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">*Main&gt; foldl progressive ([1..10],0) r</span><br style="font-family: courier,monaco,monospace,sans-serif;"><span style="font-family: courier,monaco,monospace,sans-serif;">([6],49)</span><br><br>Function f generates the roll cycle outcomes which are then folded with the progressive betting system.<br><br>In the final answer, the [6] is what's left of the original betting list [1..10]. The betting list is used to determine the bet: always bet the (first + last) of betting list. If a win, delete the first and last. If a loss, add loss to end of betting list. The 49 is winnings, initially 0.<br><br>There's no explanation in the book of what should happen if the betting list becomes empty, or a singleton, but that could be fixed by
 making it longer.<br><br>Comments, criticism, and better ways of doing it are welcome.<br><br>Michael<br style="font-family: courier,monaco,monospace,sans-serif;"><br><br>--- On <b>Fri, 12/17/10, David Leimbach <i>&lt;leimy2k@gmail.com&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: David Leimbach &lt;leimy2k@gmail.com&gt;<br>Subject: Re: [Haskell-cafe] Why is Haskell flagging this?<br>To: "michael rice" &lt;nowgate@yahoo.com&gt;<br>Cc: haskell-cafe@haskell.org, "Daniel Fischer" &lt;daniel.is.fischer@googlemail.com&gt;<br>Date: Friday, December 17, 2010, 7:45 PM<br><br><div id="yiv1169519856">No problem. &nbsp;Haskell is a different animal than even other functional languages in my experience, and it takes time to get used to the coolness in the type system, the lazy evaluation, the point free style, functional composition and all the other interesting techniques you now
 have at your fingertips for writing very expressive code :-).<div>
<br></div><div><div>Do that for a while then go back to algol based languages, and wonder why the heck anyone uses those on purpose :-). &nbsp;(yeah there's good reasons to use them, but it starts to feel confining)</div><div>
<br></div><div>Dave</div><div><div><br><div class="yiv1169519856gmail_quote">On Fri, Dec 17, 2010 at 4:28 PM, michael rice <span dir="ltr">&lt;<a rel="nofollow" ymailto="mailto:nowgate@yahoo.com" target="_blank" href="/mc/compose?to=nowgate@yahoo.com">nowgate@yahoo.com</a>&gt;</span> wrote:<br><blockquote class="yiv1169519856gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font: inherit;" valign="top">Hi, all.<br><br>Plenty of answers. Thank you.<br><br>Putting the list in the IO monad was deliberate. Another one I was looking at was<br>
<br>f :: String -&gt; IO String<br>f s = do return s<br><br>main = do ios &lt;- f "hello"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fmap tail ios<br><br>which worked fine<br><br>So, the big error was trying to add&nbsp; 1 + [1,2,3,4,5].<br><br>I considered that I needed an additional fmap and thought I had tried<br>
<br>fmap (fmap (1+)) iol<br><br>but must have messed it up, because I got an error. I guess I was on the right track.<br><br>I like to try various combinations to test my understanding. It's kind of embarrassing when I get stumped by something simple like this, but that's how one learns.<br>
<br>Thanks again,<br><br>Michael<br><br>--- On Fri, 12/17/10, Daniel Fischer
 &lt;<a rel="nofollow" ymailto="mailto:daniel.is.fischer@googlemail.com" target="_blank" href="/mc/compose?to=daniel.is.fischer@googlemail.com">daniel.is.fischer@googlemail.com</a>&gt; wrote:<br><br><br>&nbsp;&nbsp;&nbsp; From: Daniel Fischer &lt;<a rel="nofollow" ymailto="mailto:daniel.is.fischer@googlemail.com" target="_blank" href="/mc/compose?to=daniel.is.fischer@googlemail.com">daniel.is.fischer@googlemail.com</a>&gt;<br>
&nbsp;&nbsp;&nbsp; Subject: Re: [Haskell-cafe] Why is Haskell flagging this?<br>&nbsp;&nbsp;&nbsp; To: <a rel="nofollow" ymailto="mailto:haskell-cafe@haskell.org" target="_blank" href="/mc/compose?to=haskell-cafe@haskell.org">haskell-cafe@haskell.org</a><br>&nbsp;&nbsp;&nbsp; Cc: "michael rice" &lt;<a rel="nofollow" ymailto="mailto:nowgate@yahoo.com" target="_blank" href="/mc/compose?to=nowgate@yahoo.com">nowgate@yahoo.com</a>&gt;<br>
&nbsp;&nbsp;&nbsp; Date: Friday, December 17, 2010, 4:24 PM<div class="yiv1169519856im"><br><br>&nbsp;&nbsp;&nbsp; On Friday 17 December 2010 18:04:20, michael rice wrote:<br>&nbsp;&nbsp;&nbsp; &gt; I don't understand this error message. Haskell appears not to understand<br>
&nbsp;&nbsp;&nbsp; &gt; that 1 is a Num.<br>&nbsp;&nbsp;&nbsp; &gt;<br></div><div class="yiv1169519856im">&nbsp;&nbsp;&nbsp; &gt; Prelude&gt; :t 1<br>&nbsp;&nbsp;&nbsp; &gt; 1 :: (Num t) =&gt; t<br>&nbsp;&nbsp;&nbsp; &gt; Prelude&gt; :t [1,2,3,4,5]<br>&nbsp;&nbsp;&nbsp; &gt; [1,2,3,4,5] :: (Num t) =&gt; [t]<br>&nbsp;&nbsp;&nbsp; &gt; Prelude&gt;<br>
&nbsp;&nbsp;&nbsp; &gt;<br>&nbsp;&nbsp;&nbsp; &gt;
 Michael<br>&nbsp;&nbsp;&nbsp; &gt;<br>&nbsp;&nbsp;&nbsp; &gt; ===================<br>&nbsp;&nbsp;&nbsp; &gt;<br>&nbsp;&nbsp;&nbsp; &gt; f :: [Int] -&gt; IO [Int]<br>&nbsp;&nbsp;&nbsp; &gt; f lst = do return lst<br>&nbsp;&nbsp;&nbsp; &gt;<br>&nbsp;&nbsp;&nbsp; &gt; main = do let lst = f [1,2,3,4,5]<br>&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fmap (+1) lst<br>
<br></div>&nbsp;&nbsp;&nbsp; The fmap is relative to IO, your code is equivalent to<br><br>&nbsp;&nbsp;&nbsp; do let lst = (return [1,2,3,4,5])<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fmap (+1) lst<br><br>&nbsp;&nbsp;&nbsp; ~&gt;<br><br>&nbsp;&nbsp;&nbsp; fmap (+1) (return [1,2,3,4,5])<br><br>&nbsp;&nbsp;&nbsp; ~&gt;<br><br>
&nbsp;&nbsp;&nbsp; do lst &lt;- return [1,2,3,4,5]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return $ (+1) lst<br><br>&nbsp;&nbsp;&nbsp; but there's no instance Num [Int] in scope<br><br>&nbsp;&nbsp;&nbsp; You probably
 meant<div class="yiv1169519856im"><br><br>&nbsp;&nbsp;&nbsp; do let lst = f [1,2,3,4,5]<br></div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fmap (map (+1)) lst<div class="yiv1169519856im"><br><br>&nbsp;&nbsp;&nbsp; &gt;<br>&nbsp;&nbsp;&nbsp; &gt; ===============================<br>&nbsp;&nbsp;&nbsp; &gt;<br>&nbsp;&nbsp;&nbsp; &gt; Prelude&gt; :l test<br>
&nbsp;&nbsp;&nbsp; &gt; [1 of 1] Compiling Main&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ( test.hs, interpreted )<br>&nbsp;&nbsp;&nbsp; &gt;<br>&nbsp;&nbsp;&nbsp; &gt; test.hs:5:17:<br>&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp;&nbsp;&nbsp; No instance for (Num [Int])<br>&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arising from the literal `1' at test.hs:5:17<br>
&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp;&nbsp;&nbsp; Possible fix: add an instance declaration for (Num [Int])<br>&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp;&nbsp;&nbsp; In the second argument of `(+)', namely `1'<br>&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp;&nbsp;&nbsp; In the first argument of
 `fmap', namely `(+ 1)'<br>&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp;&nbsp;&nbsp; In the expression: fmap (+ 1) lst<br>&nbsp;&nbsp;&nbsp; &gt; Failed, modules loaded: none.<br>&nbsp;&nbsp;&nbsp; &gt; Prelude&gt;<br><br><br></div>--- On <b>Fri, 12/17/10, Daniel Fischer <i>&lt;<a rel="nofollow" ymailto="mailto:daniel.is.fischer@googlemail.com" target="_blank" href="/mc/compose?to=daniel.is.fischer@googlemail.com">daniel.is.fischer@googlemail.com</a>&gt;</i></b> wrote:<br>
<blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Daniel Fischer &lt;<a rel="nofollow" ymailto="mailto:daniel.is.fischer@googlemail.com" target="_blank" href="/mc/compose?to=daniel.is.fischer@googlemail.com">daniel.is.fischer@googlemail.com</a>&gt;<br>
Subject: Re: [Haskell-cafe] Why is Haskell flagging this?<br>To: <a rel="nofollow" ymailto="mailto:haskell-cafe@haskell.org" target="_blank" href="/mc/compose?to=haskell-cafe@haskell.org">haskell-cafe@haskell.org</a><br>Cc: "michael rice" &lt;<a rel="nofollow" ymailto="mailto:nowgate@yahoo.com" target="_blank" href="/mc/compose?to=nowgate@yahoo.com">nowgate@yahoo.com</a>&gt;<br>
Date: Friday, December 17, 2010, 4:24 PM<br><br><div><div class="yiv1169519856im">On Friday 17 December 2010 18:04:20, michael rice wrote:<br>&gt; I don't understand this error message. Haskell appears not to understand<br>&gt; that 1 is a Num.<br>
&gt;<br></div><div class="yiv1169519856im">&gt; Prelude&gt; :t 1<br>&gt; 1 :: (Num t) =&gt; t<br>&gt; Prelude&gt; :t [1,2,3,4,5]<br>&gt;
 [1,2,3,4,5] :: (Num t) =&gt; [t]<br>&gt; Prelude&gt;<br>&gt;<br>&gt; Michael<br>&gt;<br>&gt; ===================<br>&gt;<br>&gt; f :: [Int] -&gt; IO [Int]<br>&gt; f lst = do return lst<br>&gt;<br>&gt; main = do let lst = f [1,2,3,4,5]<br>
&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fmap (+1) lst<br><br></div>The fmap is relative to IO, your code is equivalent to<br><br>do let lst = (return [1,2,3,4,5])<br>&nbsp;&nbsp;&nbsp;fmap (+1) lst<br><br>~&gt;<br><br>fmap (+1) (return [1,2,3,4,5])<br><br>~&gt;<br>
<br>do lst &lt;- return [1,2,3,4,5]<br>&nbsp;&nbsp;&nbsp;return $ (+1) lst<br><br>but there's no instance Num [Int] in scope<br><br>You probably meant<div class="yiv1169519856im"><br><br>do let lst = f [1,2,3,4,5]<br></div>&nbsp;&nbsp;&nbsp;fmap (map (+1)) lst<div class="yiv1169519856im">
<br><br>&gt;<br>&gt; ===============================<br>&gt;<br>&gt; Prelude&gt; :l test<br>&gt; [1 of 1] Compiling Main&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ( test.hs, interpreted
 )<br>&gt;<br>&gt; test.hs:5:17:<br>&gt; &nbsp;&nbsp;&nbsp; No instance for (Num [Int])<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; arising from the literal `1' at test.hs:5:17<br>&gt; &nbsp;&nbsp;&nbsp; Possible fix: add an instance declaration for (Num [Int])<br>&gt; &nbsp;&nbsp;&nbsp; In the second argument of `(+)', namely `1'<br>
&gt; &nbsp;&nbsp;&nbsp; In the first argument of `fmap', namely `(+ 1)'<br>&gt; &nbsp;&nbsp;&nbsp; In the expression: fmap (+ 1) lst<br>&gt; Failed, modules loaded: none.<br>&gt; Prelude&gt;<br><br></div></div></blockquote></td></tr></tbody></table>
<br>

      <br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a rel="nofollow" ymailto="mailto:Haskell-Cafe@haskell.org" target="_blank" href="/mc/compose?to=Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a rel="nofollow" target="_blank" href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div></div></div>
</div></blockquote></td></tr></table><br>