Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Programming style
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===== Haskell ===== [[Haskell]], like Python, has the ''off-side rule''. It has a two-dimension syntax where indenting is meaningful to define blocks (although, an alternate syntax uses curly braces and semicolons). Haskell is a declarative language, there are statements, but declarations within a Haskell script. Example: <syntaxhighlight lang="haskell"> let c_1 = 1 c_2 = 2 in f x y = c_1 * x + c_2 * y </syntaxhighlight> may be written in one line as: <syntaxhighlight lang="haskell"> let {c_1=1;c_2=2} in f x y = c_1 * x + c_2 * y </syntaxhighlight> Haskell encourages the use of [[literate programming]], where extended text explains the genesis of the code. In literate Haskell scripts (named with the <code>lhs</code> extension), everything is a comment except blocks marked as code. The program can be written in [[LaTeX]], in such case the <code>code</code> environment marks what is code. Also, each active code paragraph can be marked by preceding and ending it with an empty line, and starting each line of code with a greater than sign and a space. Here an example using LaTeX markup: <syntaxhighlight lang="haskell"> The function \verb+isValidDate+ test if date is valid \begin{code} isValidDate :: Date -> Bool isValidDate date = hh>=0 && mm>=0 && ss>=0 && hh<24 && mm<60 && ss<60 where (hh,mm,ss) = fromDate date \end{code} observe that in this case the overloaded function is \verb+fromDate :: Date -> (Int,Int,Int)+. </syntaxhighlight> And an example using plain text: <syntaxhighlight lang="haskell"> The function isValidDate test if date is valid > isValidDate :: Date -> Bool > isValidDate date = hh>=0 && mm>=0 && ss>=0 > && hh<24 && mm<60 && ss<60 > where (hh,mm,ss) = fromDate date observe that in this case the overloaded function is fromDate :: Date -> (Int,Int,Int). </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)