Neon is a practical standard library for PureScript.
-- Find the sum of all the multiples of 3 or 5 below 1000.
-- <https://projecteuler.net/problem=1>
import Neon
main :: Eff (console :: CONSOLE) Unit
main = 1
:upTo 999
:filter (divisibleBy 3 || divisibleBy 5)
:sum
:printNeon is written from the ground up to be useful and coherent. It has some guiding principles:
-
If something is possible in JavaScript (and not a terrible idea), it should be possible in Neon. This means you can do
"ab" + "cd", but you can't do"ab" + 3. -
Functions should take their subject last. This means
add x yis reallyy + x. Consider calling functions with:, likey :add x. -
Everything should be documented with examples. Type signatures are not a substitute for documentation.
-
Laws should not prohibit useful instances. This means you can use
oron booleans and arrays. -
There should be no type class hierarchy. This means
HasZerodoes not implyHasAdd. If you need both, add both to your type signature. -
There should be as few operators as possible. This means
<$>does not exist. Usemapinstead. -
There should be one obvious way to do things. This means
returnis not an alias forpure. In fact, it doesn't exist at all. -
Functions should be defined in type classes. This means
addcan be used for both numbers and strings. -
Type classes should be as small as possible. This means the
Boundedtype class is split intoHasBottomandHasTop. -
Type classes should be designed for programmers, not mathematicians. This means
HasAddis a semigroup, but it's not calledSemigroup. -
Neon should not define its own data types. That means you can use
MaybefromData.Maybewithout translation. -
Pure functions should not throw exceptions. This means
fromIntreturns aMaybevalue. Pure functions that throw exceptions should be marked unsafe. -
Qualified imports are annoying, and fewer imports are better. This mean
import Neonis enough. No need for tens of lines of imports.