<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 18 August 2016 at 20:51, Sven Panne <span dir="ltr"><<a href="mailto:svenpanne@gmail.com" target="_blank">svenpanne@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">2016-08-17 16:37 GMT+02:00 Harendra Kumar <span dir="ltr"><<a href="mailto:harendra.kumar@gmail.com" target="_blank">harendra.kumar@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>ghc accepts a flag and its argument as a single quoted or escaped argument as well. For example all of the following are equivalent:</div><div><br></div><div>ghc -package foo </div><div>ghc "-package foo"</div><div>ghc -package\ foo</div><div><br></div><div>Is this by design or accidental? </div></div></blockquote><div><br></div></span><div>I would call this a bug, probably some missing quoting somewhere: Most commands I know don't do splitting on the arguments for themselves. Just try e.g.</div><div><br></div><div> gcc "-v -v"</div></div></div></div></blockquote><div><br></div><div>Initially I too thought the same but then I did some more testing and it turned out that the way ghc does not really parse it exactly in the same way as independent unquoted arguments. It only parses a flag which takes an argument. For example:</div><div>ghc "-package foo" -- parses foo as an argument to the -package flag</div><div>ghc "-package foo -v" -- is not the same as "-package foo" and "-v" arguments passed independently, it is "foo -v" as the argument to "-package"</div><div><br></div><div>So it essentially allows packing a flag and its argument together. Which provides a nice way to pass flags and their values as a single unit. This may be accidental to begin with but I liked this just because it makes passing opaque flags combined with arguments from a wrapper program like runghc much more convenient. I cannot think of any downside of this behavior unless someone points out otherwise.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>This has a nice side effect to make passing ghc arguments via rughc simple. For example runghc "-package foo" or runghc -package\ foo will pass "-package foo" to ghc. The alternative and documented way to achieve the same effect is runghc -package --ghc-arg=foo which is not that convenient.</div><div><br></div><div>My question is - can we rely on this way of parsing? If it is not by design, does it make sense to legalize and therefore document this?</div></div></blockquote><div><br></div></span><div>And my question is: Can we fix this bug? :-D If this is not considered a bug, we should be very explicit about this deviation from standard behavior in the documentation, including the reasons for it.</div></div></div></div></blockquote><div><br></div><div>As I explained above, I would prefer to keep this bug :-) and document it especially for runghc as a better alternative to --ghc-arg=foo . So instead of saying:</div><div>
<p class=""><span class="">runghc -package --ghc-arg=text -package --ghc-arg=turtle hello.hs</span></p></div><div>We can just say:</div><div>
<p class=""><span class="">runghc "-package text" "-package turtle" hello.hs</span></p></div><div><br></div><div> -harendra</div></div></div></div>