Continuation from yesterday’s discussion:
What are some concrete examples of where PureScript shines compared to other languages?
This would be nice to document for folks considering learning PS who do not have a background in Haskell.
A comparison to TypeScript would be really nice. Here’s what I’ve come up with so far:
- The type system is unsound. This is intentional for compatibility with existing JS. Note that mutability plays a role in breaking the example in the previous link. Lots more type system issues can be found by searching the ByDesign and DesignLimitation labels.
- Discriminated Unions are the equivalent to ADTs. There’s a lot more boilerplate required to create these and pattern match on them. See this Reducer Example.
- Libraries like lodash, ramda, and fp-ts provide more FP capabilities, but more boilerplate is required, and these often fail to type check.
- If an untyped variable cannot be inferred, it defaults to the
any
type. This can be caught with the--noImplicitAny
flag, and you can weed out the rest of them withno-explicit-any
, so I wouldn’t consider this a real issue, but figured I should cover it since it came up in yesterday’s meeting.
The trade-offs compared to Elm are pretty straightforward, although might not be as obvious to users who have only known Elm. Here’s my take:
- Fewer abstractions
- Tedious JSON encoding/decoding
- No components
- Restrictive JS FFI
- No escape hatches
A great way to demonstrate these abstraction benefits would be to start with RealWorld Elm, port it to a PS TEA framework, then refactor.
I think it’s also important to acknowledge the negative trade-offs with selecting PS over TS or Elm:
- Learning curve
- Error messages (especially compared to Elm, but understandable due to abstractions).
- Performance
- Ecosystem still being developed
- Small community
- Lots of sleeve rolling required
But the good news is that a lot of the above negatives can be improved, while TS will never have a sound type system, and it’s unknown whether Elm will ever allow more abstraction in its type system.
Maybe these comparisons are more fitting for a blog post, but I think we could assemble a more comprehensive set of examples as a community effort.