<div dir="ltr"><div><a href="http://learnyouahaskell.com/input-and-output">http://learnyouahaskell.com/input-and-output</a></div><div><br></div><div>might help.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Dec 12, 2021 at 7:09 PM יהושע ולך <<a href="mailto:yehoshuapw@gmail.com">yehoshuapw@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>The important thing here, is that print is a function from a "pure" value (any type implements the Show typeclass. (similar to trait in rust, or interface in some languages))</div><div>and creates a "IO" value, which can be thought of as a IO action. inside the IO monad, that just means running it.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Dec 12, 2021 at 7:05 PM יהושע ולך <<a href="mailto:yehoshuapw@gmail.com" target="_blank">yehoshuapw@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Notice: (from ghci)</div><div><br></div><div>Prelude GHC.Stack> :t callStack </div>callStack :: CallStack<br>Prelude GHC.Stack> :t getCallStack <br>getCallStack :: CallStack -> [([Char], SrcLoc)]<br>Prelude GHC.Stack> :t getCallStack callStack<br>getCallStack callStack :: [([Char], SrcLoc)]<br>Prelude GHC.Stack> :t length (getCallStack callStack)<br><div>length (getCallStack callStack) :: Int</div><div><br></div>Prelude GHC.Stack> :t print (length (getCallStack callStack))<br><div>print (length (getCallStack callStack)) :: IO ()</div><div><br></div>Prelude GHC.Stack> :t print<br><div>print :: Show a => a -> IO ()</div><div><br></div><div><br></div><div>the `print` function takes a pure value, and creates an IO value from it.</div><div>(actually printing is an IO action. the value it prints is not)</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Dec 12, 2021 at 5:32 PM Michael Turner <<a href="mailto:michael.eugene.turner@gmail.com" target="_blank">michael.eugene.turner@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Regards,<br>
Michael Turner<br>
Executive Director<br>
Project Persephone<br>
1-25-33 Takadanobaba<br>
<br>
Shinjuku-ku Tokyo 169-0075<br>
Mobile: +81 (90) 5203-8682<br>
<a href="mailto:turner@projectpersephone.org" target="_blank">turner@projectpersephone.org</a><br>
<br>
Understand - <a href="http://www.projectpersephone.org/" rel="noreferrer" target="_blank">http://www.projectpersephone.org/</a><br>
Join - <a href="http://www.facebook.com/groups/ProjectPersephone/" rel="noreferrer" target="_blank">http://www.facebook.com/groups/ProjectPersephone/</a><br>
Donate - <a href="http://www.patreon.com/ProjectPersephone" rel="noreferrer" target="_blank">http://www.patreon.com/ProjectPersephone</a><br>
Volunteer - <a href="https://github.com/ProjectPersephone" rel="noreferrer" target="_blank">https://github.com/ProjectPersephone</a><br>
<br>
"Love does not consist in gazing at each other, but in looking outward<br>
together in the same direction." -- Antoine de Saint-Exupéry<br>
<br>
<br>
<br>
<br>
On Sun, Dec 12, 2021 at 8:48 PM <<a href="mailto:beginners-request@haskell.org" target="_blank">beginners-request@haskell.org</a>> wrote:<br>
<br>
<br>
> have another look at<br>
> <a href="https://hackage.haskell.org/packaggetCallStackgetCallStacke/base-4.16.0.0/docs/GHC-Stack.html#v:callStack" rel="noreferrer" target="_blank">https://hackage.haskell.org/packaggetCallStackgetCallStacke/base-4.16.0.0/docs/GHC-Stack.html#v:callStack</a><br>
> <<a href="https://hackage.haskell.org/package/base-4.16.0.0/docs/GHC-Stack.html#v:callStack" rel="noreferrer" target="_blank">https://hackage.haskell.org/package/base-4.16.0.0/docs/GHC-Stack.html#v:callStack</a>><br>
<br>
I'd been looking at that already, over and over. Still not seeing it.<br>
But your proposed fix does work. Thank you.<br>
> let l = getCallStack callStack<br>
> print (length l)<br>
> ```<br>
> the `getCallStack` does not return an "IO" value..<br>
<br>
And yet it's it's somehow an IO value in "print (length (getCallStack<br>
callStack))"?<br>
<br>
I just don't get this.<br>
<br>
> On Sun, Dec 12, 2021, 12:58 Michael Turner <<a href="mailto:michael.eugene.turner@gmail.com" target="_blank">michael.eugene.turner@gmail.com</a>><br>
> wrote:<br>
><br>
> > The following prints 1, as you'd expect:<br>
> > -----------------<br>
> > import GHC.Stack<br>
> ><br>
> > foo :: HasCallStack => IO ()<br>
> > foo = do<br>
> > print (length (getCallStack callStack))<br>
> ><br>
> > main =<br>
> > foo<br>
> > -------------------<br>
> > But when I make it this:<br>
> > ...<br>
> > l <- getCallStack callStack ;<br>
> > print (length l)<br>
> ><br>
> > I get all this:<br>
> > ------------------------------------------<br>
> > ...<br>
> > • Couldn't match type ‘[]’ with ‘IO’<br>
> > Expected type: IO ([Char], SrcLoc)<br>
> > Actual type: [([Char], SrcLoc)]<br>
> > • In a stmt of a 'do' block: l <- getCallStack callStack<br>
> > In the expression:<br>
> > do l <- getCallStack callStack<br>
> > print (length l)<br>
> > In an equation for ‘foo’:<br>
> > foo<br>
> > = do l <- getCallStack callStack<br>
> > print (length l)<br>
> > |<br>
> > 5 | l <- getCallStack callStack ;<br>
> > | ^^^^^^^^^^^^^^^^^^^^^^<br>
> > --------------------------------------------<br>
> ><br>
> > What am I not seeing?<br>
> ><br>
> ><br>
> > Regards,<br>
> > Michael Turner<br>
> > Executive Director<br>
> > Project Persephone<br>
> > 1-25-33 Takadanobaba<br>
> ><br>
> > Shinjuku-ku Tokyo 169-0075<br>
> > Mobile: +81 (90) 5203-8682<br>
> > <a href="mailto:turner@projectpersephone.org" target="_blank">turner@projectpersephone.org</a><br>
> ><br>
> > Understand - <a href="http://www.projectpersephone.org/" rel="noreferrer" target="_blank">http://www.projectpersephone.org/</a><br>
> > Join - <a href="http://www.facebook.com/groups/ProjectPersephone/" rel="noreferrer" target="_blank">http://www.facebook.com/groups/ProjectPersephone/</a><br>
> > Donate - <a href="http://www.patreon.com/ProjectPersephone" rel="noreferrer" target="_blank">http://www.patreon.com/ProjectPersephone</a><br>
> > Volunteer - <a href="https://github.com/ProjectPersephone" rel="noreferrer" target="_blank">https://github.com/ProjectPersephone</a><br>
> ><br>
> > "Love does not consist in gazing at each other, but in looking outward<br>
> > together in the same direction." -- Antoine de Saint-Exupéry<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><img src="https://projecteuler.net/profile/yehoshua.png"><br></div><div dir="ltr"><br></div></div></div></div>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><img src="https://projecteuler.net/profile/yehoshua.png"><br></div><div dir="ltr"><br></div></div></div></div>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><img src="https://projecteuler.net/profile/yehoshua.png"><br></div><div dir="ltr"><br></div></div></div></div>