Now and then I try to make progress with PureScript. While I do not buy the condemnation of Elm, I see situations where I could benefit from PureScript. During my last attempt to make progress with PureScript I managed to figure out how to use flags and send POST requests. This time I want to create a simple client for https://www.thecocktaildb.com/ .
After the initial rage of coming back to PureScript after a while, and encountering the infamous error messages, I persevered and got the flags working again.
I was impressed by quick progress of the Elm example
And would like to achieve something similar this time, and perhaps see how far I could go trying to improve over the elm example.
Has anybody done something similar that can be used as an example?
To what extent should I ignore function signatures? There are situations where they are not helpful at all and send you down the wrong path. The compiler is unable to suggest a type signature that will allow the code to compile.
The imports do not show how to use H.HalogenM
How many of those examples are wrong? What is the point of having type signatures in some places and is there a way to suppress the missing type signatures?
I value type signatures rather highly. I write them before writing implementations, doing so helps me think about what the code is going to need in terms of inputs and what shape I want the output to be. It then also acts as a check to see if what Iāve done is what I intended to do, while Iām working on the implementation.
Giving up for now. After several days of trying, I was not able to recreate in PureScript a simple Elm example that took me hours in Elm.
I can not cope with the compiler misleading me about the type signatures. I was disappointed in the code needed for the ordered list. I do not find the language discoverable. Everything takes ages to figure out.
Maybe for people with mathematical thinking, itās a perfect language, but not for me. At what point does the dreaded JavaScript seem to be less frustrating?
If I see a reason to try Purescript again, youāll hear from me again.
You are suggesting it too early. I only figured out how to get the data from API service. Now I am trying to build my own autocomplete and got stuck with events.
The linked āPerforming Effectsā example demonstrates where you should use HalogenM, Component, and ComponentHTML respectively in your component ā as Gary said, I highly recommend that you write these type signatures in all of your components, as they make the compiler significantly more helpful as you work on the rest of your component.
What is the point of having type signatures in some places and is there a way to suppress the missing type signatures?
I really think youāll benefit from specifying type signatures in general, and itās usually a good idea to specify the type signature before workirg on the implementation. Not only does it make the compiler better, it helps you think through whether your implementation is going to be possible or not. Type-driven development is a natural fit for PureScript and I think youāll find it frustrating to try and avoid writing type signatures.
Iāll express a view thatās somewhat sympathetic to @bigosās. Itās a view Iāve had for a while. I didnāt think it would be widely shared in the Purescript community, but thatās OK. One of the things that I value about Purescript is that it lets me do things my way even if most Purescript users prefer a different way.
I love that type inference lets the compiler figure out types for you and tell you when youāre wrong. Leaving signatures out makes the code is less verbose, and it provides some of the exploratory benefits of a dynamically typed language like Clojure: I can try out ideas and get feedback from the compiler. Yes, without signatures, the code is less informative, but I can always ask what type the compiler has inferred.
I do add signatures sometimes when it seems helpful. I think for some kinds of projects including signatures is very important, and I also see the value of type-first programming. Itās a different way of thinking about code. Sometimes I work that way.
(Since Iām just starting out with Purescript, I havenāt written much Purescript without signatures, but Iāve written a significant amount of code that way in OCaml and Haskell. So my view is based mainly on other languages. But one of the appeals of Purescript for me is that I can leave out signatures if I want.)
Thank you for sharing that perspective. I donāt think thereās anything wrong with writing PureScript that way. But if you are struggling against the compiler then explicitly writing the type signatures you know goes a long way towards making it clear where the mismatch lies.
That is how far I got with this project. I learned a few things, and itās time to move on.
Most importantly, I have learned patience with PureScript. The errors no longer give me the feeling of rage. I just learned to ignore that part. It is difficult to explain, but it is almost like reading between the lines of the error messages. Did you experience something like that?
The compiler is talking nonsense, but I almost know what it is trying to say.