Simple TheCocktailDB example

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?

little progress

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 example:
https://purescript-halogen.github.io/purescript-halogen/guide/03-Performing-Effects.html
is not helpful.

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.

1 Like

They are useful, where they are useful. But at times, they give me nonsense and prevent me from compiling the code.

How should I handle the contradictions? How much should I battle the type signatures before giving up?

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 should provide isolated reproducible problems when asking for help IMO.

That way, you can build yourself a simple toolbox of problem/solution examples to later refer to.

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.

We have a big misunderstanding here.

Commenting out the type signature allows me to compile the code and move ahead.

The compiler can be very deceptive regarding the type signatures, leading you to go in circles.

Maybe you are a PreScript veteran, and things look different from your perspective. But I benefited from suppressing type warnings to move ahead.

I need rest from PureScript tonight, but I will come back to your comments in a few days. Maybe after a while, I will change my views.

1 Like

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.)

1 Like

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.

1 Like

Thanks @thomashoneyman–that’s helpful advice. (I ended up adding type signatures today, in fact, for just that reason.)

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.

1 Like

I found a new reason for rage! It is called CORS.