10 ms·
Make the Leap from JavaScript to PureScript
- lelf 7y agoThe repo https://github.com/adkelley/javascript-to-purescript https://github.com/adkelley/javascript-to-purescript
- draw_down 7y ago"Make the leap from JavaScript to CoffeeScript!" 5 years later: "oh no"
- tmountain 7y agoPureScript really hits the sweet spot for me, and it's become my favorite functional language over the last six months. It really feels like a purpose built stripped down Haskell without some modern refinements (string handling, records, compiles to readable JavaScript). You can easily manage dependences to incorporate the absolutely minimum set of packages necessary to run your project, and I think its safety is unparalleled. That said, the community is pretty small (but also really awesome), and it fits into what is starting to feel like a crowded space (ReasonML, Elm, ClojureScript [kind of], TypeScript, etc), but I'm still hopeful that PureScript gets some traction over the next few years and becomes more widely used in the industry, as it is a fantastic language and deserves to be more widely recognized. Also, if anyone is looking to try PureScript with minimal effort, I threw together this guide a while back: https://github.com/tmountain/purescript-reproducible https://github.com/tmountain/purescript-reproducible
- the_duke 7y ago> without some modern refinements Did you mean "with some modern refinements" ? Otherwise, I agree. String handling, vectors, and record namespacing/access are quite annoying legacy burdens of Haskell, improved upon in Purescript. The type system lacks some of the power, but is sufficient for most designs IMO.
- tmountain 7y agoSorry, yes, that was a typo.
- sridca 7y agoDon't forget GHCJS, which is really handy as you get to share (Haskell) code between client and server. Here's an example from my own project: https://github.com/srid/Taut https://github.com/srid/Taut
- edem 7y agoWhat about making the leap from javascript to a real programming language?
- lcfcjs2 7y agoA primitive slow-ass programming compiled language? No thanks.
- algem 7y agoWhat defines a “real” programming language?
- deleted 7y ago[deleted]
- dang 7y agoPlease don't post unsubstantive comments here.
- edem 7y agoI didn't do that this was a legitimate question. Apart form that if you're not a mod you really can't tell me what to do.
- dang 7y agoI'm afraid I am a mod. If you throw around a term like "real programming language" in that way, that's flamebait, which isn't ok here. Would you mind reviewing the site guidelines and taking the spirit of this site to heart when posting? We'd appreciate it. https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html
- edem 7y agoProve that you're a mod.
- darepublic 7y agoScanned the home page for any reference to how you interface with the browser API in purescript. Is it any different than in js?
- ff_ 7y agoMost of if is already wrapped in a well-maintained package: https://pursuit.purescript.org/packages/purescript-web-dom/2.0.0 https://pursuit.purescript.org/packages/purescript-web-dom/2... But doing FFI and just using JS when needed is very easy: https://github.com/purescript/documentation/blob/master/language/FFI.md https://github.com/purescript/documentation/blob/master/lang... So, to answer the question: no, it's exactly as in JS, because _it is_ JS
- dmix 7y agoThe biggest problem with PureScript right now is so many of the libraries have little traditional documentation. They often just include generated module level type/function docs as in the `purescript-web-dom` one you linked to. Meanwhile the developer just wants a quick overview and some examples of querying the DOM in order to evaluate it. I tried using PureScript last year but I was having dependency problems like crazy. Largely because everything was very alpha and dependency chains were unreliable. It's good to see the community maturing, there's still some way to go first, which is excepted with any new language. I might try it out again this weekend as I'm a fan of Haskell.
- ff_ 7y agoAgreed. Documentation is hard in all languages though, and it usually gets fixed slowly over time as langs mature. If you had dependency problems you were likely using bower (where dependencies are "resolved", and this leads to broken states in some cases). You might want to try a "package set" approach instead - i.e. there's a curated set of library versions that are known to work together, so "dependency problems" become impossible for users: https://github.com/spacchetti/spago https://github.com/spacchetti/spago
- Klathmon 7y agoDoes anyone have any experience with both PureScript and ReasonML that can compare the 2?
- bcheung 7y agoI had this exact same question and couldn't find much out there. Based on what I have seen ReasonML is being pushed more within the React community and has more of a JS syntax so there is less of an abrupt change in terms of language. PureScript follows the Haskell syntax that I personally like more and find cleaner and more useful for FP programming. The ReasonML code I've seen doesn't have as much computer science rigor or abstractions like monads. This means the ReasonML community generally works at a lower level of abstraction compared to the PureScript crowd. The interop with JS looks a cleaner in PS. The tooling looks better around ReasonML especially around fast compilation and automatic reloading. PureScript has a richer type system. Personally, I would rather use PS but I've studied Haskell a bit already. For people without the Haskell background ReasonML provides an easier transition so it is an easier sell for a team.
- jahewson 7y agoPureScript is heavily influenced by Haskell with a focus on purity, monads and lots of abstraction, while Reason is literally OCaml (which has a more pragmatic take on mutability) only they switched the ML syntax for a JS-like syntax.
- nobleach 7y agoDuring the 2016-2017 New Year I did an intense look into Purescript. I bought the LeanPub book and did all kinds of stuff with it. More recently I did a look into ReasonML. I bought the Pragprog book and worked through that. For me, it came down to Haskell vs OCaml. I'll admit, I have a serious love for OCaml/F#, so I immediately was excited about ReasonML. Many concepts just transferred very easily. Purescript felt very academic once I got into trying to build real things. Watching Phil Freeman's talks/Google Hangouts on building cool new projects really was eye-opening. That guy thinks on an entirely new level... who knows, maybe most Haskellers do? I have a sincere appreciation for Haskell, but I have yet to bend my mind around it, so Purescript left me in the same place - I felt like I wasn't really grokking it. I should stress that this is ME, so you may have an entirely different experience. I'm not saying that Purescript was bad at all.... it just wasn't clicking very well.
- jaequery 7y agoQuestion is why? What’s better about PureScript that would make other FP programmers (eg; Elm) choose over it?
- eweise 7y agoMore powerful abstractions that reduce the amount boilerplate compared to Elm.
- ff_ 7y agoOne of the biggest reasons for me is that you can run it on the backend too (on NodeJS, or Erlang, or some other VM - yes, there are several backends available)
- _bxg1 7y agoAnything that targets JS, including Elm, can in theory be run on Node.
- cryptica 7y agoI don't buy this idea that the programming language you use determines the quality of your work. There is no evidence to support this. These extreme programming fads were invented to sell books. If novelists followed the same approach as programmers and they kept trying to find the perfect language to write their books in, they wouldn't manage to publish a single interesting novel. A language cannot prevent someone from making stupid mistakes. At best, it solves one set of familiar problems and replaces them with a new set of unfamiliar (but equally bad) problems; then you have to learn to cope with those new problems until the next hyped-up language fad comes along claiming to solve those new problems and then you repeat the cycle.
- UnFleshedOne 7y agoTry writing something in machine code?
- adrianN 7y agoHuman languages had a few thousand more years of optimization going on. By now they're pretty decent for expressing things people want to say.
- feanaro 7y ago> A language cannot prevent someone from making stupid mistakes. Completely prevent all possible mistakes? Of course not. However, it certainly can make many mistakes either impossible or much rarer.
- phailhaus 7y agoYou're making too many extreme claims to be defensible. You might have a point for recent language fads, but choice of language absolutely does have an impact on your work and the nature of the bugs you're going to be dealing with. If you choose to use a language with a poor ecosystem, then you're going to have to build a lot more tools in house that are going to be subpar compared to more vigorously maintained libs and frameworks in another language. If you decide to write in JavaScript, then you're going to introduce bugs that TypeScript would have statically checked against. It all depends on the nature of your problem and what tradeoffs you're willing to make.
- automathematics 7y agoThis just reminds me of "Make the Leap from Javascript to Coffeescript" Remember where that got us? This stuff is all really cool and fun to work on, but instead maybe we should focus on changing the JS standard for the better since we always end up working in it anyways! https://js.foundation/ https://js.foundation/
- phailhaus 7y agoYes, it got us ES6! Languages don't exist in a vacuum. They introduce new ideas, dispense with others, and all languages can learn from what works in the field and what doesn't. If you're working on a personal project, it might be a good idea to try out PureScript and learn from what it has to teach!
- automathematics 7y agoYay new ECMA standards! Classes/decorators/scope/arrow functions have made my life SO MUCH BETTER the last 5 years
- ARandomerDude 7y agoWhy not both? CoffeeScript was awesome at the time, and ahead of its time. JavaScript owes many of its new niceties to CoffeeScript. Yes, please, let's advance the state of JS. And let's push the boundaries with other languages that don't have the backwards-compatibility constraints and corporate sluggishness that JavaScript does. Then take the best features and merge them into JS.
- automathematics 7y agoYeah it was awesome! But then years later most projects are wasting engineering time to convert their whole code base which is a bummer! That's all I'm saying.
- bcheung 7y agoThe JS community is adopting more and more concepts but a lot of it has to do with the syntax. If the syntax is too verbose people just won't use it. FP is much easier when working with a language based off the lambda calculus (Haskell, Elm, PureScript, etc). Currying, partial application, and point-free composition is overly verbose in JS. JS has adopted the concepts but they are not used very often because of the messy and noisy syntax.
- srean 7y agoI do not do any web related programming but was quite intrigued and impressed by a language called Opa. Could anyone watching this space comment on what is happening in the Opa world.
- _bxg1 7y agoWhat distinguishes PureScript from Elm?
- crimsonalucard 7y agotype variables, type classes, parametric polymorphism. Elm is similar to golang missing generics, its a large gaping hole.
- kadblas 7y agoA resource that covers more of these questions is covered here: https://github.com/JordanMartinez/purescript-jordans-reference/blob/latestRelease/00-Getting-Started/01-Why-Learn-PureScript.md https://github.com/JordanMartinez/purescript-jordans-referen... Not all of it is up-to-date or presents the best arguments one could muster. Rather, it's goal is to be "good enough." Also related (but unfortunately not yet finished): https://github.com/chexxor/purescript-documentation-discussion/blob/50351c1aae8346c0f24125157316476ebb310db8/02-Context-or-Narrative/State-of-PureScript-Documentation-2019.md https://github.com/chexxor/purescript-documentation-discussi... See these repos for an example of the language in action: - https://github.com/jordanmartinez/purescript-jordans-reference https://github.com/jordanmartinez/purescript-jordans-referen... - https://github.com/jordanmartinez/learn-halogen https://github.com/jordanmartinez/learn-halogen - https://github.com/thomashoneyman/purescript-halogen-realworld/ https://github.com/thomashoneyman/purescript-halogen-realwor...
- mpweiher 7y agoMisread as "Make the Leap from JavaScript to PostScript". Now that I would have been on board with!! :-)
- gridlockd 7y agoI'm put off (not because of the formatting): http://try.purescript.org/?session=60f1839b-bd82-d9af-75ef-dcd936c4a0a2 http://try.purescript.org/?session=60f1839b-bd82-d9af-75ef-d... It adds weird syntax where it doesn't matter, like "<>" for string concatenation, but it doesn't cut down on noise where it does matter, i.e. the "list of records" in the example. I'm also wary of a language that puts "pure" right in the name. Purity is nice and often beneficial, but there's a point where it just becomes a crutch. That point which is where the FP adherents and the mainstream diverge.
- lelf 7y agoIt’s not a syntax, it’s just a function (<>). Also how would you ”improve” list of records?
- gridlockd 7y ago> It’s not a syntax, it’s just a function (<>) Doesn't matter, it's annoying to type and read. What's wrong with '+'? (Rhetorical question, nothing is wrong with '+') > Also how would you ”improve” list of records? Admittedly, I had not thought of a better solution, but it looks noisy where supposedly such a language should look "clean". Perhaps something like this: examples:{title:string, gist:string} = [ { "Algebraic Data Types", "37c3c97f47a43f20c548" } { "Loops", "cfdabdcd085d4ac3dc46" } { "Operators", "3044550f29a7c5d3d0d0" } { "Records", "b80be527ada3eab47dc5" } { "Recursion", "ff49cc7dc85923a75613" } { "Do Notation", "47c2d9913c5dbda1e963" } { "Type Classes", "1a3b845e8c6defde659a" } { "Generic Programming", "3f735aa2a652af592101" } { "QuickCheck", "69f7f94fe4ff3bd47f4b" } ]
- ulucs 7y agoPutting addition and concatenation under the same operator massively backfires when you start using math libraries. All of the language semantics is thrown out of the window when you can realistically sum or concatenate the same two elements, but the operator can only be used for one case (example: python and numpy). For the list of examples, you can just use tuples if you want the "clean" look. There is no need to change the record semantics which is the same in almost all languages.
- deleted 7y ago[deleted]
- paul7986 7y agoWhat about HypeScript..anyone using that?
- Leace 7y agoI've been thinking about using PureScript years ago as I've enjoyed the PureScript by Example book [0] and the language that seems like a cleaned-up version of Haskell. I didn't like that the compiler is not written in PureScript (although there was a proof of concept [1]. Additionally, even though it compiles to JavaScript, the code that is generated is sub-optimal performance-wise [2]. Ultimately I used TypeScript and have been happy with that but still long for better FP language that generates lean code and can be used in a browser. [0]: https://leanpub.com/purescript/read https://leanpub.com/purescript/read [1]: https://github.com/purescript/purescript-in-purescript https://github.com/purescript/purescript-in-purescript [2]: https://github.com/purescript/purescript/issues/2577 https://github.com/purescript/purescript/issues/2577
- huy-nguyen 7y agoI'm also concerned about PureScript's JS output so I looked into ReasonML and has been quite impressed. The type system is a bit less powerful (no type classes yet) but the JS output is very readable and maps almost line-to-line to ReasonML code.
- kepano 7y agoWe use PureScript for almost all frontend happening at my company, Lumi (YC W15). We're definitely biased towards functional programming since we use Haskell on the backend, and the creator of PureScript, Phil Freeman, works here as Director of Engineering. We're starting to publish more about the benefits of this approach and sharing open source libraries here: https://www.lumi.dev/ https://www.lumi.dev/ Our React bindings are interesting to look at if you are curious: https://github.com/lumihq/purescript-react-basic https://github.com/lumihq/purescript-react-basic
- zumu 7y agoWhat's the deal with being tied to bower as the package manager?
- toastal 7y agoIt isn't necessarily though. A lot of people are using Spago (https://github.com/spacchetti/spago https://github.com/spacchetti/spago). Bower is fine though for how they're using it. Often times it'd kill for the ability to relink libraries locally like bower lets you do in Elm while working through a PR of an external library for my use-case.
- hkai 7y agoTypescript.