Avoid blank line separating code and comments in Bird style?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Avoid blank line separating code and comments in Bird style?

R Sidhu
Hi

This regarding GHC behaviour for literate Haskell programs in Bird
style. GHC expects a blank line between comment[1] and code.
Otherwise, during the literate pre-processor stage, the error
'unlit: Program line next to comment' is reported.

While above behaviour makes sense in general, there are situations
where one would like to place comments adjacent to code with no
intervening blank line. For example, in documenting a declaration
using Haddock (in standard, non-literate Haskell), as shown in
sections 3.1 and 3.2 of the Haddock User Guide, no blank line
separates comment and code.

Any way to enable GHC to accept Bird style literate programs with
no blank lines separating comment and code?

[1] 'Comment' (in context of Bird style) refers to text on lines not
beginning with '>'.

Regards
Sidhu

_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Avoid blank line separating code and comments in Bird style?

Mateusz Kowalczyk
On 01/13/2015 10:28 AM, R Sidhu wrote:

> Hi
>
> This regarding GHC behaviour for literate Haskell programs in Bird
> style. GHC expects a blank line between comment[1] and code.
> Otherwise, during the literate pre-processor stage, the error
> 'unlit: Program line next to comment' is reported.
>
> While above behaviour makes sense in general, there are situations
> where one would like to place comments adjacent to code with no
> intervening blank line. For example, in documenting a declaration
> using Haddock (in standard, non-literate Haskell), as shown in
> sections 3.1
> <https://www.haskell.org/haddock/doc/html/markup.html#idm140354810917952>
> and 3.2 <http://www.haskell.org/haddock/doc/html/ch03s02.html> of the
> Haddock User Guide, no blank line
> separates comment and code.
>
> Any way to enable GHC to accept Bird style literate programs with
> no blank lines separating comment and code?
>
> [1] 'Comment' (in context of Bird style) refers to text on lines not
> beginning with '>'.
>
> Regards
> Sidhu
>
>

I don't understand the motivation here. If you want to use Haddock with
literate Haskell it has to look something like

> -- | Foo
> someCode = undefined

I believe it does not matter to GHC whether we give it

-- | Foo, no blank line
someCode = undefined


or


-- | Foo, blank line

someCode = undefined


Haddock would see both as just someCode with a comment attached.

I imagine you're suggesting that something like


Literate comment
> someCode = undefined


is allowed but your justification using Haddock doesn't make sense in
this case: ‘Literate comment’ will not be visible.

Correct me if I'm wrong on anything here, I very rarely use the .lhs .

--
Mateusz K.
_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Avoid blank line separating code and comments in Bird style?

R Sidhu
At Wed, 14 Jan 2015 12:31:54 +0530,
Mateusz Kowalczyk wrote:

> I imagine you're suggesting that something like

> Literate comment
> > someCode = undefined

This (literate comment followed by code with no intervening blank
line) is exactly what I want (regret my explanation was unclear). But
when I try it, GHC reports the error 'unlit: Program line next to
comment'.

> is allowed ...

As you mention above behaviour is allowed, could you let me know how
to enable it?

Regards
Sidhu
_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Avoid blank line separating code and comments in Bird style?

Richard Eisenberg-2
I think the underlying problem here is that there is a difference between "literate" comments and "normal" comments.

In a bird-style literate Haskell file, this is what I'll call a literate comment:

~~~
A line with no marker at the beginning
~~~

A normal comment is in a line of Haskell code, put with a comment indicator:

~~~
> -- This is a "normal" comment
~~~

When GHC sees a bird-style literate Haskell file, it first strips out all lines that don't begin with >. Then, it starts doing its real work, including parsing Haddock comments. So, to use a Haddock comment in a literate Haskell file, you'd need to use the "normal" comment style:

~~~
> -- | Make a numbered widget
> mkWidget :: Int -> Widget
~~~

There is no way to use Haddock markup in a "literate" comment.

But, as Mateusz points out, there may be blank lines between the Haddock comment and the thing being described:

~~~
> -- | Get the number of a widget
>
> widgetNum :: Widget -> Int
~~~

I hope this clarifies things!
Richard


On Jan 14, 2015, at 2:42 AM, sidhu1f <[hidden email]> wrote:

> At Wed, 14 Jan 2015 12:31:54 +0530,
> Mateusz Kowalczyk wrote:
>
>> I imagine you're suggesting that something like
>
>> Literate comment
>>> someCode = undefined
>
> This (literate comment followed by code with no intervening blank
> line) is exactly what I want (regret my explanation was unclear). But
> when I try it, GHC reports the error 'unlit: Program line next to
> comment'.
>
>> is allowed ...
>
> As you mention above behaviour is allowed, could you let me know how
> to enable it?
>
> Regards
> Sidhu
> _______________________________________________
> Glasgow-haskell-users mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Avoid blank line separating code and comments in Bird style?

R Sidhu
At Wed, 14 Jan 2015 10:55:41 -0500,
Richard Eisenberg wrote:

>
> I think the underlying problem here is that there is a difference between "literate" comments and "normal" comments.
>
> In a bird-style literate Haskell file, this is what I'll call a literate comment:
>
> ~~~
> A line with no marker at the beginning
> ~~~
>
> A normal comment is in a line of Haskell code, put with a comment indicator:
>
> ~~~
> > -- This is a "normal" comment
> ~~~
>
> When GHC sees a bird-style literate Haskell file, it first strips out all lines that don't begin with >. Then, it starts doing its real work, including parsing Haddock comments. So, to use a Haddock comment in a literate Haskell file, you'd need to use the "normal" comment style:
>
> ~~~
> > -- | Make a numbered widget
> > mkWidget :: Int -> Widget
> ~~~
>
> There is no way to use Haddock markup in a "literate" comment.
>
> But, as Mateusz points out, there may be blank lines between the Haddock comment and the thing being described:
>
> ~~~
> > -- | Get the number of a widget
> >
> > widgetNum :: Widget -> Int
> ~~~

I understand and agree with all you say above...
 
> I hope this clarifies things!

...but unfortunately it doesn't solve my problem. I guess my attempt
to motivate with the Haddock use case confused things.

What I want to do has nothing to do with Haddock. All I would like is,
very simply (in Bird style) literate comment and code next to each
other with No Intervening Blank Lines separating them. But GHC doesn't
accept this and GHC reports the error 'unlit: Program line next to
comment'. If I add a blank line between the literate comment and code,
GHC accepts it.

Summarizing, following is accepted by GHC without error (notice blank
line separating literate comment and code):

   literate comment
   
   > haskell code

For following GHC reports error, but it is what I require:

   literate comment
   > code

So. Is there any way GHC can be coaxed to accept a Bird style literal
Haskell file with no blank line separating code and literal comment?

> Richard
>

Sidhu


>
> On Jan 14, 2015, at 2:42 AM, sidhu1f <[hidden email]> wrote:
>
> > At Wed, 14 Jan 2015 12:31:54 +0530,
> > Mateusz Kowalczyk wrote:
> >
> >> I imagine you're suggesting that something like
> >
> >> Literate comment
> >>> someCode = undefined
> >
> > This (literate comment followed by code with no intervening blank
> > line) is exactly what I want (regret my explanation was unclear). But
> > when I try it, GHC reports the error 'unlit: Program line next to
> > comment'.
> >
> >> is allowed ...
> >
> > As you mention above behaviour is allowed, could you let me know how
> > to enable it?
> >
> > Regards
> > Sidhu
> > _______________________________________________
> > Glasgow-haskell-users mailing list
> > [hidden email]
> > http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>


_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Avoid blank line separating code and comments in Bird style?

Andres Löh
Hi everyone.

I think invoking GHC(i) with -optL-q might work.

Cheers,
  Andres

--
Andres Löh, Haskell Consultant
Well-Typed LLP, http://www.well-typed.com

Registered in England & Wales, OC335890
250 Ice Wharf, 17 New Wharf Road, London N1 9RF, England
_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Reply | Threaded
Open this post in threaded view
|

Re: Avoid blank line separating code and comments in Bird style?

R Sidhu
At Wed, 14 Jan 2015 18:12:31 +0100,
Andres Löh wrote:
>
> Hi everyone.
>
> I think invoking GHC(i) with -optL-q might work.

Solved my problem! My thanks to you Andres (and to Mateusz and Richard
also).

>
> Cheers,
>   Andres
>

Sidhu
_______________________________________________
Glasgow-haskell-users mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users