<div dir="ltr"><br><br><div class="gmail_quote">On Sun, Aug 17, 2008 at 8:45 PM, Paul Jarc <span dir="ltr"><<a href="mailto:prj@po.cwru.edu">prj@po.cwru.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I have a Haskell script called "notify", without a .hs extension,<br>
which causes some problems. (I'm using ghc <a href="http://6.8.3." target="_blank">6.8.3.</a>)<br>
<br>
First attempt: runhaskell notify<br>
Without the .hs extension, ghc doesn't know it's a Haskell script, and<br>
so I get "Could not find module `notify'". Maybe runhaskell should<br>
automatically add "-x hs" to the ghc command?<br>
<br>
Second attempt: runhaskell -x hs notify<br>
This get me "Not in scope: `main'". runhaskell is invoking ghc with<br>
these arguments:<br>
-ignore-dot-ghci -x -e ':set prog "hs"' -e ':main ["notify"]' hs<br>
So it looks like runhaskell it treating "-x" as an argument to be<br>
relayed to ghc, "hs" as the name of the script, and "notify" as an<br>
argument to the script. I guess I need to use "--" to make it clear<br>
where the ghc arguments end and where the script and its arguments<br>
begin.<br>
<br>
Third attempt: runhaskell -- -x hs -- notify<br>
This gets me "Not in scope: `main'" again. runhaskell is invoking ghc<br>
with these arguments:<br>
-ignore-dot-ghci -x -e ':set prog "hs"' -e ':main ["--","notify"]' hs<br>
This looks like a bug in the "--" handling, unless I'm misinterpreting<br>
the usage message I get from running plain "runhaskell".<br>
<br>
Fourth attempt: ghc -ignore-dot-ghci -e ':set prog "notify"' \<br>
-e ':main []' -x hs notify<br>
This works, but passing arguments becomes rather cumbersome. If<br>
there's a way to get runhaskell to pass "-x hs" in the right place,<br>
that would be much better.<br>
<br>
A somewhat related issue: I'd like to avoid hard-coding the path to<br>
runhaskell or ghc in the #! line. Instead, I'd like to use #!/bin/sh,<br>
and have the shell find runhaskell or ghc in $PATH. </blockquote><div><br>I'll let someone more knowledgeable address the other issues, but as for the argument to #!, I believe you could/should use "#!/usr/bin/env runhaskell".<br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">This means the<br>
first few lines of the script would have to be executed by sh, but<br>
ignored by ghc. Most scripting langauges have some way of doing this,<br>
although it's often by accident. The best way I've seen is in Guile,<br>
where "#!" starts a multi-line comment, and "!#" ends it. For<br>
Haskell, this is the best I could come up with:<br>
<br>
#!/bin/sh<br>
{- > /dev/null 2>&1<br>
exec ghc -ignore-dot-ghci \<br>
-e ":set prog \"$0\"" \<br>
-e ':main []' -x hs "$0"<br>
-}<br>
<br>
But this depends on "{-" not existing as an executable command, or at<br>
least not doing anything harmful when invoked like this. I'd like to<br>
avoid depending on anything like that. Does anyone have any better<br>
ideas?<br>
</blockquote><div><br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
<br>
paul<br>
_______________________________________________<br>
Glasgow-haskell-users mailing list<br>
<a href="mailto:Glasgow-haskell-users@haskell.org">Glasgow-haskell-users@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/glasgow-haskell-users" target="_blank">http://www.haskell.org/mailman/listinfo/glasgow-haskell-users</a><br>
</blockquote></div><br></div>