Content deleted Content added
Stevebroshar (talk | contribs) →Scripting: Clarify |
Stevebroshar (talk | contribs) →Examples: Merge Ada and Haskell into group section |
||
Line 457:
</syntaxhighlight>
===
A relatively loose collection of languages use <code>--</code> for a single line comment. Notable languages include: [[Ada (programming language)|Ada]] and [[Haskell]]. An example in Ada:
<syntaxhighlight lang="ada">
</syntaxhighlight>
====Block in Haskell====▼
In Haskell, a block comment is delimited by <code>{-</code> and <code>-}</code>. For example:
<syntaxhighlight lang="Haskell">▼
{- this is a comment▼
on more lines -}▼
-- and this is a comment on one line▼
putStrLn "Wikipedia" -- this is another comment▼
</syntaxhighlight>▼
Haskell also provides a [[literate programming]] method of commenting known as "Bird Style".<ref>{{cite web |url=http://www.haskell.org/haskellwiki/Literate_programming#Bird_Style |title=Literate programming |website=haskell.org}}</ref>
<syntaxhighlight lang="lHaskell">▼
In Bird-style you have to leave a blank before the code.▼
> fact :: Integer -> Integer▼
> fact 0 = 1▼
> fact (n+1) = (n+1) * fact n▼
And you have to leave a blank line after the code as well.▼
</syntaxhighlight>▼
Literate programming can also be accomplished via [[LaTeX]]. Example of a definition:
<syntaxhighlight lang="lHaskell">▼
\usepackage{verbatim}▼
\newenvironment{code}{\verbatim}{\endverbatim}▼
</syntaxhighlight>▼
Used as follows:
<syntaxhighlight lang="lhaskell">▼
% the LaTeX source file▼
The \verb|fact n| function call computes $n!$ if $n\ge 0$, here is a definition:\\▼
\begin{code}▼
fact :: Integer -> Integer▼
fact 0 = 1▼
fact (n+1) = (n+1) * fact n▼
\end{code}▼
Here more explanation using \LaTeX{} markup▼
</syntaxhighlight>▼
===By language===
====APL====
Line 596 ⟶ 637:
print '(A)', 'Hello world' ! Fortran 90 introduced the option for inline comments.
end program
▲</syntaxhighlight>
▲====Haskell====
▲<syntaxhighlight lang="Haskell">
▲{- this is a comment
▲on more lines -}
▲-- and this is a comment on one line
▲putStrLn "Wikipedia" -- this is another comment
▲</syntaxhighlight>
▲Haskell also provides a [[literate programming]] method of commenting known as "Bird Style".<ref>{{cite web |url=http://www.haskell.org/haskellwiki/Literate_programming#Bird_Style |title=Literate programming |website=haskell.org}}</ref> In this all lines starting with > are interpreted as code, everything else is considered a comment. One additional requirement is that you always leave a blank line before and after the code block:
▲<syntaxhighlight lang="lHaskell">
▲In Bird-style you have to leave a blank before the code.
▲> fact :: Integer -> Integer
▲> fact 0 = 1
▲> fact (n+1) = (n+1) * fact n
▲And you have to leave a blank line after the code as well.
▲</syntaxhighlight>
▲<syntaxhighlight lang="lHaskell">
▲\usepackage{verbatim}
▲\newenvironment{code}{\verbatim}{\endverbatim}
▲</syntaxhighlight>
▲<syntaxhighlight lang="lhaskell">
▲% the LaTeX source file
▲The \verb|fact n| function call computes $n!$ if $n\ge 0$, here is a definition:\\
▲\begin{code}
▲fact :: Integer -> Integer
▲fact 0 = 1
▲fact (n+1) = (n+1) * fact n
▲\end{code}
▲Here more explanation using \LaTeX{} markup
</syntaxhighlight>
|