Live data from Hacker News

How to write PureScript react components to replace JavaScript

thomashoneyman.com

71–74 of 74 posts

Re: How to write PureScript react components to replace JavaScript

#71
post #67
post #55

Earlier quoted context omitted.

I would phrase the question as "why would you write Typescript when we have Purescript (or ReasonML)"? Why would you choose to write a language who's type system is much less expressive than languages like Purescript? Why not have that expressive power and its ability to prevent some classes of bugs, and still have good interop with JS?

I was actually thinking, why would you use purescript for react, when you could use reasonml? https://reasonml.github.io/reason-react/docs/en/components https://reasonml.github.io/reason-react/docs/en/usestate-eve... As far as I can tell the integration is cleaner and has better support from upstream? I guess it's not Haskell - but I really would be interested in why you would choose purescript for this use-case (per…

No, I actually prefer Reason.

I'm happy to argue the benefits of either. The differences between it and Purescript are much smaller than the differences between them and most things.

Re: How to write PureScript react components to replace JavaScript

#72

Earlier quoted context omitted.

There's something attractive about this example but i'm struggling to figure out why i think that. What is it that makes this attractive? + There's a signal to noise ratio that's off the charts + You've not cheated to achieve succinctness; there's no blackbox.nowDrawTheRestOfTheOwl() - I don't think that's "pretty" code - i don't find it easy to parse, i had to read your example with my index finger pressed against t…

Just curious: what’s your level of fluency with Clojure/lisp syntax vs C-style syntax? I found that learning to read the lisp-style indentation (which is purely by convention but has widespread acceptance and tooling support) was a pretty fast process with a solid payoff. It becomes easier to jump between levels of detail, and I now find it to be more readable than C-style syntax, even though I only write JS for work…

Yeah i agree the readability is purely a lack of familiarity on my part rather than some fundamental difficulty in the syntax.

If anything, the clojure syntax has fewer rules to understand - from my very limited knowledge of it.

Re: How to write PureScript react components to replace JavaScript

#73
post #12

Earlier quoted context omitted.

Also, you can get compile-time strict typing in Typescript with some minor annotations added to that: export const Counter: FunctionComponent void }> = ({ label, counterType, onClick }) => { const [counter, setCounter] = useState (0); return ( { counterType == "Increment" && setCounter(counter + 1); counterType == "Decrement" && setCounter(counter - 1); onClick && onClick(); }}> {label}: {counter} ); }

Yes. You can add types if you want. And maybe one can discuss if there is a more elegant syntax than the C-style syntax of JavaScript (there is ...). Other than that. I think the code is about as concise as it gets.

There is a change I’d make though - I’d memo-ise the click handler with useCallback. By using the function ‘overload’ on setState, which is guaranteed not to change, the callback will only be calculated (?) when the onclick handler changes. The setState would look like this: setState(c => c + 1);. Right now, the callback is interpreted on every render cycle.

Re: How to write PureScript react components to replace JavaScript

#74
post #55
post #23

Why would anyone write purescript when we have typescript?

I would phrase the question as "why would you write Typescript when we have Purescript (or ReasonML)"? Why would you choose to write a language who's type system is much less expressive than languages like Purescript? Why not have that expressive power and its ability to prevent some classes of bugs, and still have good interop with JS?

The reason for typescript is support and uptake; it 'feels' enough like C#/Java for many people to jump on. Purescript & ReasonML feel alien to most developers.
Post reply on HN