| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
This is a style guide for the Haskell code that comprises the PureScript compiler. The recommended style guide for PureScript code is available here.
This page is a work in progress; compiler maintainers should currently feel free to debate and edit this document until it stops being contentious, at which point we may migrate it into the repo proper.
In rough order from most to least important—that is, you can read each point as if it were followed by ‘when this doesn't conflict with a previous point’.
Try to format comments to wrap around 80 characters, and find ways to break up lines of code that are longer than 120-ish characters. If readability isn't served by this guideline, ignore it.
Generally: two spaces, no tabs. When indentation is used to align elements of a syntactic form that spans multiple lines, use the indentation in a way that doesn't require every line to change if the initial line changes (principle 2).
Show codeChoose one:
data Either a b = Left a | Right bdata Either a b
= Left a
| Right bDo not write:
data Either a b = Left a
| Right bChoose one:
foo :: forall a. ClassName a => Either Text a -> a -> afoo
:: forall a
. ClassName a
=> Either Text a
-> a
-> aDo not write:
foo :: forall a
. ClassName a
=> Either Text a
-> a
-> aChoose one:
foo a b = bar a . baz $ qux bfoo a b
= bar a
. baz
$ qux bDo not write:
foo a b = bar a
. baz
$ qux bUse sparingly?
Do use a custom data type instead of a Bool if at least one of the following applies:
Do declare a data type as a record if it has only one constructor and at least one of the following applies:
Consider do notation if:
Avoid do notation if none of the above apply and:
Use infix notation for functions with the following names:
Don't use infix notation for functions which would otherwise not merit it, just to avoid using flip: flip f x is equivalent to (`f` x), but the former is generally more readable. (???)
Avoid catch-all patterns unless your logic is truly agnostic to new constructors being added to the type being matched.
Example Do write:-- | Extract the value of a Foo.
maybeFooValue = \case
Foo value -> Just value
_ -> NothingDo not write:
-- | Extract a wibble, which is something that may or may not be present in any ctor.
findWibble = \case
Foo wibble -> Just wibble
Bar _ wibble -> Just wibble
_ -> NothingWhen matching a data type, use the empty record pattern (CtorName{}) instead of wildcards (CtorName _ _) if the logic of the case would not change if new fields were added to that constructor.
Prefer lambda-case to multiple equational declarations, when possible. (This follows from principle 2; repeating the name of the function means more places to edit if that function is renamed.)
| Back | FazBrowse Home | New Git URL |