Better HN
topnewbestaskshowjobs
Log inSign up

purescript

96 karma · joined Nov 12, 2014 (12y ago) · 59 submissions

purescript.org
Submissions

comment 10y ago · link · parent

> Still, type classes seem to appear less and less elegant as time goes on

I think part of the problem is that type classes are so easy to abuse. When you have a problem like e.g. monad transformers, where a) you have a lot of boilerplate code which would be irksome if written out by hand, b) you have laws to make sure the generated code is sensible, and c) your types have exactly one such sensible instance, then classes are very nice. Abuses of type classes exist where any of the three above conditions fail to hold IMO, and a scrap-your-typeclasses approach can be very valuable then.

comment 10y ago · link · parent

I haven't used latest Halogen yet, so I can't give a detailed comparison, but the approach in Thermite [1] is indeed what I am referring to above. It was based on some work in the OpticUI library [2], and has worked out quite nicely for the few projects I have applied it to.

I will say that the types in Halogen seem more complex, but they can be justified by the fact that the coproduct machinery helps ensure all actions get handled somewhere. This may be possible with prisms, I'm not sure yet. This library [3] seems relevant.

One issue I've found, which I understand the Halogen folks are also finding, is that it is tricky to wire up action handlers such that a subcomponent can invoke an action and have a parent act on it and invoke its own action in response. Granted, this is a relatively infrequent use case, and you can always push such logic into some shared parent.

[1]: https://github.com/paf31/purescript-thermite/ [2]: https://github.com/zrho/purescript-optic-ui [3]: https://github.com/joneshf/purescript-totally

comment 10y ago · link · parent

I know there is the Focus library [1]. I'm not sure about prisms, traversals etc.

[1] http://package.elm-lang.org/packages/evancz/focus/1.0.1/Focu...

comment 10y ago · link · parent

I've found lenses (for zooming state) and prisms (for zooming actions) to be very useful for solving this problem.

comment 11y ago · link · parent

My answer to this has changed quite a bit over the last year. It used to be the case, at least as I saw it, that Elm had a UI focus, and PureScript tried to be a general-purpose language. So it came down to typical expressiveness vs. tooling/analysis tradeoffs. You could use Elm and maybe sacrifice some general-purpose language features like dealing with arbitrary effects, but buy yourself best-in-class tools like their excellent time-traveling debugger, and hot code reloading. Or you could pick PureScript, and have a general-purpose language which ran in a bunch of environments with lots of native libraries, but at the expense of tooling.

Now though, Elm has become a more general-purpose language, adding effects and various other features, and PureScript has better UI libraries and tooling/editor support. So the gap has closed somewhat.

Speaking generally, the goals of the two projects are pretty similar. I can't speak for the Elm community, but "bring strongly-typed FP to the JavaScript community via the web platform" seems to approximate the goals of both projects pretty well (maybe someone from the Elm side can correct me here?) So the goals are similar, but the execution is very different. I think Elm and PureScript differ greatly in opinions regarding _how_ to bring strongly-typed FP to JavaScript. This is not just a question of language features (type classes and HKTs are often mentioned), but also things like how the language should present its foreign function interface to JavaScript, what the entry point to an application should look like, whether to build features into the language or in libraries, how to grow a language community, etc. In practice, these make the experience of using each language very different.

> when would we want one vs. the other?

Elm provides tools with which you can become productive quickly. Also, it's used in production by NoRedInk and others, so it's clear that it is general-purpose enough to be used for real applications. I think there will be two paths to PureScript for most users - from Haskell, and from JavaScript, quite possibly via Elm. Just as users might move to Elm because they want type safety and expressiveness, they might move to PureScript because they find themselves wanting even more type safety and expressiveness. Certain abstractions are possible in PureScript, but (I think, again, would be glad to be corrected..) not in Elm - free monads, monad transformers, monadic tail calls, van Laarhoven lenses, etc. SlamData is an example of an (open source) company putting these tools to great use.

comment 11y ago · link · parent

> I wish all these alt-JS-haskellish language authors (of PureScript, Elm, Roy, etc.) would just work on making GHCJS better.

All three of those have very different goals and trade-offs from GHCJS.

I agree that it would be nice to share more work/knowledge though. One of the nice things about AltJS is that several languages can coexist in the same codebase.

comment 11y ago · link · parent

I hope you find PureScript has improved considerably since you last looked, but if you have any specific issues, please drop into #purescript IRC and let us know.

comment 11y ago · link · parent

There are some PureScript projects that I know of running on Node, although it is admittedly less common. I'm currently working on a framework to build REST services in PureScript, so hopefully the situation will improve shortly.

comment 11y ago · link · parent

The largest all-PureScript application I know of is SlamData[0], which takes about 12s for a rebuild, but SlamData uses a _lot_ of modules. For smaller projects it's much less. It's not great, but performance is one of three main goals for the current milestone. There is an alternative front-end called psc-compile[1] which reduces the incremental build times considerably. I hope to be able to integrate it soon.

  [0] slamdata.com
  [1] github.com/bitc/purescript/tree/psc-compile/psc-compile

comment 11y ago · link · parent

Monad transformers and PureScript's row-based effects are two complementary approaches to the problem of extensible effects.

Some effects in PureScript look a lot like the effects provided by certain monad transformers (StateT/ST/Ref, ExceptT/Exception, etc.), but there are differences in terms of how things compose. Take StateT and ExceptT for example: you can compose them in two ways, and get two different monad transformer stacks, with different behaviors (surrounding how state propagates when an exception occurs). There are valid use cases for each, but with the ST and Exception effects, there is only one way to combine them: the way the underlying (Javascript) runtimes chooses for us.

There are things which each one can do which the other cannot. Fortunately, we can mix and match in PureScript since we have the purescript-transformers library. A typical arrangement is to stick Eff on the bottom of a monad transformer stack.

_Edit_: of course, everything you can do with a monad transformer can be done more verbosely with pure functions and the underlying monad, so you _could_ replace monad transformers with Eff in many cases, but in practical terms, it might not be all that useable in some cases.

comment 11y ago · link · parent

I don't know Alice ML but one advantage of using abstractions like Applicative is that you can write code which is polymorphic in the particular applicative you choose. So, you can mock your concurrent requests using the Identity or ZipList applicative, and use the type class laws to prove things which are true about both. I'm guessing, but it looks like the spawn syntax is built-in here. Not that it's not as elegant as the Concurrent version, but likely not as powerful from an abstraction point of view.

comment 11y ago · link · parent

An Applicative functor is a type constructor which lets you lift functions of arbitrary numbers of arguments to functions whose arguments are wrapped with that type constructor.

Concretely, if you think about promises in JavaScript, for example, if you have a function A -> B -> C -> D, say, and you have three promises of types Promise A, Promise B and Promise C, you can construct a Promise of type Promise D by running the three in parallel, and applying your three-argument function when they are all done. So you've turned a function of type A -> B -> C -> D into one of type Promise A -> Promise B -> Promise C -> Promise D. If you can do that sensibly for any number of function arguments, you have an Applicative. ("sensibly" here means that there are type class laws which have to hold)

Every Monad is also an Applicative functor, since you could use do notation to compose your promises instead, but there are other interesting Applicatives which do not come from Monads.

comment 11y ago · link · parent

One thing I find surprisingly effective is that I write a todo list on paper every morning, and check items off as they get done. I keep a longer todo list of personal goals on a Trello board.

comment 11y ago · link · parent

s/minor/major

45.

purescript-halogen – A declarative, type-safe UI library for PureScript(github.com ↗)

13 points · by purescript · 11y ago · discuss

comment 11y ago · link · parent

/s/Pure Script/PureScript :)

comment 11y ago · link · parent

Right now, the translation is very direct. My basic rule of thumb is - only perform those optimizations which the user opts into. Some things are standard though, like a few inlining rules and tail call elimination, but the plan is to provide a rewrite rules engine so that the developer can be as fine-grained as they like when it comes to optimizations.

comment 11y ago · link · parent

I can't really comment on source maps in Elm, but the approach in PureScript has been to generate clean, readable JS which is debuggable directly. Source maps are on the roadmap, but not really a priority right now. I haven't heard any complaints about the ability to debug compiled PureScript yet.

comment 11y ago · link · parent

I won't argue that Elm does anything other than an exemplary job at #3, but it is worth noting that there are some interesting efforts to build similar functionality in PureScript libraries:

https://github.com/paf31/purescript-thermite

https://github.com/kRITZCREEK/reactive-psc

https://github.com/bodil/purescript-signal

https://github.com/michaelficarra/purescript-demo-mario

https://github.com/mechairoi/purescript-frp-rabbit

To me, this is the benefit of PureScript - yes, you have to do a little more work, because you don't get these things for free from the compiler and tools, but you gain complete control over your application structure. You're not forced to work in some ambient Signal category.

comment 11y ago · link · parent

Maybe https://github.com/paf31/purescript-thermite ...

comment 11y ago · link · parent

I tried to change the whitespace rules in the PureScript parser to match Haskell recently (to support explicit braces), and it proved to be very difficult. The "L" function which is defined in the Haskell 98 Report depends heavily on an interaction between the lexer and parser, in which a failed parse causes the indenter to behave differently in the lexer. For this reason, I stayed with the simpler rules that we have now, and I plan to support explicit braces in the parser instead.

comment 11y ago · link · parent

> There is purescript but its a large layer over javascript and even a simple hello world results in a 2000 LOC compilation of javascript.

This really depends on which compilation route you take. `psc-make` will include all of the Prelude and compile to CommonJS modules, which can result in quite a bit of code, but `psc` will trim out all unused functions, and should result in about 10 LOC for Hello World.

53.

PureScript 0.6 Released(github.com ↗)

1 points · by purescript · 12y ago · discuss

54.

Show HN: A step-by-step MicroKanren evaluator(functorial.com ↗)

3 points · by purescript · 12y ago · discuss

12