<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jun 5, 2013 at 3:56 PM, Roman Cheplyaka <span dir="ltr">&lt;<a href="mailto:roma@ro-che.info" target="_blank">roma@ro-che.info</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">* Ivan Lazar Miljenovic &lt;<a href="mailto:ivan.miljenovic@gmail.com">ivan.miljenovic@gmail.com</a>&gt; [2013-06-05 17:47:40+1000]<br>

<div><div class="h5">&gt; On 5 June 2013 17:34, Roman Cheplyaka &lt;<a href="mailto:roma@ro-che.info">roma@ro-che.info</a>&gt; wrote:<br>
&gt; &gt; * Jason Dagit &lt;<a href="mailto:dagitj@gmail.com">dagitj@gmail.com</a>&gt; [2013-06-04 21:00:25-0700]<br>
&gt; &gt;&gt; &gt; My preferred solution would be to have ghc/ghci automatically run hsc2hs<br>
&gt; &gt;&gt; &gt; (support c2hs also?) when necessary.  But so long as it&#39;s handled<br>
&gt; &gt;&gt; &gt; automatically, I wouldn&#39;t be particularly bothered by the implementation.<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; How about having a `ghci` command for cabal? Or does the automatic<br>
&gt; &gt;&gt; requirement really need to be part of ghc to work the way you want?<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt; (BTW, cabal-dev does have a `ghci` command, but I haven&#39;t tested to<br>
&gt; &gt;&gt; see if it does the hsc -&gt; hs conversion.)<br>
&gt; &gt;<br>
&gt; &gt; I don&#39;t think cabal can provide that. Let&#39;s say you&#39;re inside a &#39;cabal<br>
&gt; &gt; ghci&#39; session. If you modify the hsc file and reload it in ghci, you&#39;d<br>
&gt; &gt; expect to load the updated version — yet cabal hasn&#39;t even been called<br>
&gt; &gt; since &#39;cabal ghci&#39;, and have had no chance to re-generate the hs file.<br>
&gt; &gt;<br>
&gt; &gt; To answer the subject question — hsc2hs is not a single preprocessor<br>
&gt; &gt; available. There are also c2hs and greencard, and maybe something else.<br>
&gt; &gt; It is (or, at least, was) not clear which one should be generally<br>
&gt; &gt; preferred. Perhaps by now hsc2hs is a clear winner — I don&#39;t know.<br>
&gt; &gt;<br>
&gt; &gt; Another option is to add a generic preprocessor option to GHC, something<br>
&gt; &gt; like -pgmX cmd. Then, for hsc2hs one would write something like<br>
&gt; &gt;<br>
&gt; &gt;   {-# OPTIONS_GHC -pgmX hsc2hs #-}<br>
&gt;<br>
&gt; Isn&#39;t this what -pgmF is<br>
&gt; for?<a href="http://www.haskell.org/ghc/docs/7.6.1/html/users_guide/options-phases.html#replacing-phases" target="_blank">http://www.haskell.org/ghc/docs/7.6.1/html/users_guide/options-phases.html#replacing-phases</a><br>

&gt;<br>
&gt; {-# OPTIONS_GHC -F -pgmF hsc2hs #-}<br>
<br>
</div></div>Indeed! I should&#39;ve read the whole section.<br>
<br>
Problem solved, then?</blockquote><div><br></div><div style>Pretty close.  For anyone who wants to use hsc2hs in this way, the first step is to create a wrapper script to handle the arguments appropriately (otherwise the output doesn&#39;t go to the proper location)</div>
<div style><br></div><div style>&gt; file ghc_hsc2hs.sh</div><div style>&gt;   #!/bin/sh</div><div style>&gt;   hsc2hs $2 -o $3</div><div style><br></div><div style>Put the wrapper in your path, and add</div><div style>{-# OPTIONS_GHC -F -pgmF ghc_hsc2hs.sh #-}</div>
<div style><br></div><div style>to the top of the source file.  The source file must have a .hs extension for ghci to load it, but hsc2hs will ignore that and process it anyway.</div><div style><br></div><div style>With this you can load the file in ghci, and if you modify the file reloading in ghci will pick up the changes, so it works pretty nicely.</div>
<div style><br></div><div style>There are a couple drawbacks though.  First, this isn&#39;t good for distribution because other people won&#39;t have your wrapper script.  Second, this preprocessor stage comes after CPP, which might impose some difficulties in certain cases.</div>
<div style><br></div><div style>I can see this working well for internal projects etc.  If hsc2hs (and other preprocessors) were distributed in a fashion suitable for use with -F, either directly or by providing a wrapper, I think this could become the preferred workflow.  I&#39;m not entirely pleased that a non-Haskell file gets a .hs extension, but c&#39;est la vie.</div>
<div style><br></div><div style>I think it would generally be useful if ghc&#39;s -F phase were to support non-Haskell files, but that&#39;s probably a bit more work than just distributing a pgmF-friendly hsc2hs.</div></div>
</div></div>