Guide to learn purescript

Hi everyone, i’m currently learning purescript and need to be guided, can someone point me step by step learning purescript from bottom up and how long it will take to be productive with it? and maybe some tips
background from javascript (typescript) and Rescript to build NextJs app.

my goal is to be productive in purescript and write halogen or nextjs with purescirpt (Really need for SSR)

i’ve read some of:

don’t get me wrong those book are awesome and detail especially Jordans Reference, maybe my brain just get overwhelmed by a lot of new technique.

i’m feeling stuck, and need light :joy:
btw, i’m sorry for my poor english

2 Likes

I think Jordan’s reference and the PureScript book are basically the go-to learning resources currently.

I’d say that mostly depends on your functional language background, but I don’t really have a concrete answer.

I think the most important tip is this: whenever you have a question or get stuck, just ask. The community around PureScript is very helpful, so whenever you’re unsure of something or get stuck, just ask here or on Slack.

What are you stuck on exactly?

2 Likes

Thanks for the response

do i really need to learn everything from Jordans and Purescript book to be productive? e.g MTL and Free Monad

1 Like

Nope, I’ve been using PS for years – even stumbling my way through writing libraries people actually use – and have only recently started understanding MTL (understanding is a strong word, I get by :sweat_smile:). I’ve also never used a free monad, that I’m aware of. I did end up having to learn indexed monads to write a specific library, but didn’t need them before or after.

You’ll be able to do plenty just with these:

  • basic types (defining them, pattern matching)
  • functions (currying, forall, typeclass constraints)
  • monads (do-notation, Effect, Aff, traverse)
  • FFI (working with external javascript, unless you aren’t doing this then it doesn’t matter)
  • tooling (spago mostly, sometimes pulp/bower/npm)

And when you’re comfortable with that stuff it’ll be a lot easier to look into a specific, more difficult topic as you need it.

14 Likes

ah, thank i’ll keep in mind. one more question, does type-level programming in purescript used in production?
i’m interested to learn more

You don’t need to know MTL or the Free monad to write programs. Some of the scripts I wrote when we were migrating the ecosystem from v0.13.x to v0.14.0 used Aff entirely just to get stuff done. You will already get 70% of PureScript’s benefits over say JavaScript via strong types, pure functions, pattern matching, type classes and Aff, etc.

Generally, one will start using MTL / Free when they want to be more careful and specific about “what” can happen “where.” It also tends to help a lot when testing your code. If you were writing a larger app among a team where each person owns part of that codebase, you might start using them more.

Type-level programming (as well as other more advanced features of the type system) can be used in production, but one has to be careful about the “power-to-weight” ratio. TLP gets complicated fast, so sometimes the benefits it provides aren’t worth the mental cost of TLP gymnastics.

Also, part of the reason why I wrote my reference work was because I read through the “Haskell from First Principles” book and got lost at monad transformers. I think Haskell’s newtype syntax is what messed me up initially.
If there was one transformer I would learn, it would be ReaderT as it provides a way to access the values you put into the environment at any point in your code.

Keep asking questions either on here or on Slack when you get stuck. We’ve all sat in your place at one time or another, and appreciated the help we got from those farther along the path.

13 Likes

Talking about mtl, Im curious how many people here have used it for testing. I always find myself using it only to later instantiate with a single App monad :slight_smile:

2 Likes

thank for the advice, now i see some light.
and thank to your amazing work Jordan’s Reference

Thanks! And if you run into any problems or feel like something could be better explained, open an issue.

1 Like

I picked up Purescript just over a month ago. The most functional-type of programming I’d ever done before was RxJS in Angular. The most expressive type-system I’d ever used belongs to Java (Maybe TypeScript is more expressive in theory, but in practice anything complicated just gets done with any).

How long it will take to be productive with it?

I’ve gone from nearly zero understanding to being able to solve most of the problems I could solve in other languages. I wouldn’t say I’m productive with it yet, but I can solve some real problems so I’m not too far away.

I also think the “you’re productive with this technology” bar is way lower than is typically insinuated. Each new abstraction you learn and master increases your productivity, but the baseline that gets you moving isn’t bad at all. A purely functional language like Purescript complicates that story a little bit, but I’ve been pleasantly surprised with how a very little gets you a long way.

Of course, mileage will differ for everybody.

I think your background with Rescript and NextJS will give you a running start compared with my path. For example: it took me an embarrassingly long time before it finally clicked just how absurdly useful currying is.

You should have an easy enough time understanding Maybe (Rescript’s optional) and abstract data types (Kinda like Rescript’s varient).


My number one recommendation is to pick and solve an exercise problem. Something just complex enough that the process of prototyping/solving it will run you into the standard roadblocks. Since it’s just a small exercise problem you can avoid being bogged down too much with design and such. That way you can focus on the language.

For front-end stuff, the canonical exercise problem is the “todo” list. I would avoid that one. I would start with something that focuses more on purescript than on web. You can always build a minimal Web-UI for just about anything.

Write an algorithm that guides a robot through a room. Or an algorithm that guides an elevator up and down floors (see if it can maximize efficiency by some metric like distance moved, average time spent in the elevator, or average time spent waiting for the elevator). Or a traffic simulator. All easy algorithms that have all been solved elsewhere but that can easily add a bit of extra complexity where needed to help you learn.

I built a Sudoku Solver. Peter Norvig wrote a python solution in about 100 lines of code, but it’s also easy to see how such a solution can be expanded to use more involved constraints to make fewer guesses. Or how this could be expanded with a UI. Or altered so that the steps of the algorithm can be animated.


Here’s a link to what I slowly built with my spare time over the past month or so. The thing itself, well, it’s … okay. The learning it represents is awesome though :slight_smile:

Do something fun and energizing while you’re learning. Save the tedious stuff for later :stuck_out_tongue:

8 Likes

Indeed, “todo” list is overrated (IMHO)

That’s really cool project, i don’t know how sudoku works, tho

thank for the idea, i’ll keep in mind

2 Likes

FWIW, I’ve been working on and off on a book to teach functional programming in Purescript. It’s far from finished and probably way too basic at the moment (it’s geared towards those who are complete newcomers to programming), but maybe something to keep a lookout for in the future.

6 Likes