<div dir="ltr">Another solution is to define `f` below `root` within the do block:<div><br></div><div>```</div><div><div style="color:rgb(33,33,33)">main' = do</div><div style="color:rgb(33,33,33)"> (root : inputFile :_) <- getArgs</div><div style="color:rgb(33,33,33)"> input <- readFile inputFile</div><div style="color:rgb(33,33,33)"> let pairs = pairFilesToContents $ readSmsnLines input</div><div style="color:rgb(33,33,33)"> let f :: (FilePath, String) -> IO ()</div><div style="color:rgb(33,33,33)"> f (name, content) = writeFile (root+name) content </div><div style="color:rgb(33,33,33)"> mapM_ f pairs</div><div style="color:rgb(33,33,33)"><span style="color:rgb(0,0,0)">```</span><br></div></div><div style="color:rgb(33,33,33)"><span style="color:rgb(0,0,0)"><br></span></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, 21 Jul 2017 at 10:07 Jeffrey Brown <<a href="mailto:jeffbrown.the@gmail.com">jeffbrown.the@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Excellent! Thanks, Alejandro!</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 21, 2017 at 12:52 AM, Alejandro Serrano Mena <span dir="ltr"><<a href="mailto:trupill@gmail.com" target="_blank">trupill@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">The problem is that in the "where" clause the only things which are in scope are (roughly) the arguments of the function. In particular, neither "root" nor "inputFile" nor "input" nor "pairs". The solution is to add an extra argument:<div><br></div><div>main' = do</div><div> ...</div><div> mapM_ (f root) pairs where</div><div> f root (name, content) = writeFile (root ++ name) content</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_1436876924990855298h5">2017-07-21 9:28 GMT+02:00 Jeffrey Brown <span dir="ltr"><<a href="mailto:jeffbrown.the@gmail.com" target="_blank">jeffbrown.the@gmail.com</a>></span>:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_1436876924990855298h5"><div dir="ltr"><div>The following compiles and runs perfectly:</div><div><br></div><div>main = do</div><div> (inputFile:_) <- getArgs</div><div> input <- readFile inputFile</div><div> let pairs = pairFilesToContents $ readSmsnLines input</div><div> mapM_ f pairs where</div><div> f :: (FilePath, String) -> IO ()</div><div> f (name, content) = writeFile name content</div><div><br></div><div>But the following triggers the error "<span style="color:rgb(0,0,0);font-family:monospace">Not in scope: ‘root’".</span></div><span style="font-family:monospace">
<br></span><div><div>main' = do</div><div> (root : inputFile :_) <- getArgs</div><div> input <- readFile inputFile</div><div> let pairs = pairFilesToContents $ readSmsnLines input</div><div> mapM_ f pairs where</div><div> f :: (FilePath, String) -> IO ()</div><div> f (name, content) = writeFile (root+name) content</div><span class="m_1436876924990855298m_4027179478070442585HOEnZb"><font color="#888888"><div><br></div></font></span></div><span class="m_1436876924990855298m_4027179478070442585HOEnZb"><font color="#888888">-- <br><div class="m_1436876924990855298m_4027179478070442585m_-804485472379460636gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Jeff Brown | Jeffrey Benjamin Brown</div><div dir="ltr"><a href="https://msu.edu/~brown202/" style="font-size:12.8px" target="_blank">Website</a> | <a href="https://www.facebook.com/mejeff.younotjeff" style="font-size:12.8px" target="_blank">Facebook</a> | <a href="https://www.linkedin.com/in/jeffreybenjaminbrown" style="font-size:12.8px" target="_blank">LinkedIn</a><span style="font-size:12.8px">(spammy, so I often miss messages here) </span><span style="font-size:12.8px">|</span><span style="font-size:12.8px"> </span><a href="https://github.com/jeffreybenjaminbrown" style="font-size:12.8px" target="_blank">Github</a><span style="font-size:12.8px"> </span></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
</font></span></div>
<br></div></div>_______________________________________________<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-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.<br></blockquote></div><br></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="m_1436876924990855298gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Jeff Brown | Jeffrey Benjamin Brown</div><div dir="ltr"><a href="https://msu.edu/~brown202/" style="font-size:12.8px" target="_blank">Website</a> | <a href="https://www.facebook.com/mejeff.younotjeff" style="font-size:12.8px" target="_blank">Facebook</a> | <a href="https://www.linkedin.com/in/jeffreybenjaminbrown" style="font-size:12.8px" target="_blank">LinkedIn</a><span style="font-size:12.8px">(spammy, so I often miss messages here) </span><span style="font-size:12.8px">|</span><span style="font-size:12.8px"> </span><a href="https://github.com/jeffreybenjaminbrown" style="font-size:12.8px" target="_blank">Github</a><span style="font-size:12.8px"> </span></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
</div>
_______________________________________________<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-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>