r/functionalprogramming • u/Ok-Tutor-4321 • Nov 07 '23
Question Best functional language for web creative coding?
I'm dabbling in functional programming, I have experience with python, go and javascript and lately I've been preferring the declarative way of doing things more (since I understood how to use list comprehension, maps and filters I no longer want to use loops lol).
I'm also learning creative coding with javascript with libraries like three.js, d3.js, p5.js, etc. And I would like to do it through a language with a stricter functional paradigm. The first one I considered was Elm, but I saw that it was complicated for working with javascript libraries outside its ecosystem. Searching I found other options like:
- Coffeescript
- ReasonML
- Rescript (I'm not sure if it's different from ReasonML)
- Civet
- Ocaml
So, I would like to know based on your experience which one may be better for creative coding. The order of my priorities is: compatibility with javascript libraries, a strong functional approach (to improve functional logic) and a minimalist syntax.
4
u/VicariousAthlete Nov 08 '23
F# with the Safe stack is pretty neat, you can use F# for front and backend, and there are some ELM-ish approaches you can use too:
https://safe-stack.github.io/
3
u/GunpowderGuy Nov 07 '23
What do you mean by minimalist syntax
22
u/sharky1337_ Nov 07 '23
What about Clojurescript ?
10
u/SV-97 Nov 07 '23
PureScript might be worth a look - AFAIK it compiles to JS and I think you can reuse JS code relatively easily
28
u/Voxelman Nov 07 '23
Elm
9
u/iams3b Nov 07 '23
Rescript has great interop with JS, especially if you're using a rendering library you're going to want to be able to bind to mutation easily.
Also it's not the same as ReasonML, ReasonML is more familiar for Ocaml developers and Rescript was forked to feel more familiar to JS developers
9
u/digitizemd Nov 07 '23
I think typescript + effect can allow you to write functional code in the style of Scala ZIO (a bit higher level than basic monoid, monad, functor primitives) while still using the javascript/typescript ecosystem.
8
u/[deleted] Nov 07 '23
Fable F#
7
u/pm_me_ur_happy_traiI Nov 07 '23
Personally I love doing FP in Typescript, which isn't explicitly minimal, but I tend to use a pretty minimal subset of language features.
7
u/Puzzleheaded-Lab-635 Nov 07 '23
ELM or Rescript, both are mature have plenty of examples to choose from and have FP principles at their core. both have great but different approaches to JS interop
6
u/mchwds Nov 07 '23
Elixir
10
u/Murky-Rough Nov 07 '23
PureScript
10
u/Brave-Gur5819 Nov 07 '23
Elm ports aren’t so bad really, depends on your needs but if creativity is the goal I’d consider Elm closely, it’s just so simple to use
4
u/XDracam Nov 08 '23
I also vote for Elm. It's insanely satisfying to change your code and know: if it compiles, you have handled all possible cases. Nothing can fail at runtime. As a consequence, code is simple, short, elegant and concrete. Compile errors are extremely friendly, and there's flawless type inference. The only downside is that reusable components are rare and rather clunky to write and use, compared to a more object oriented framework like react.
4
u/aaaaargZombies Nov 08 '23
I wouldn't be put off by the Elm JS interop. Here's a hello world example of passing a value from Elm and triggering some JS.
https://ellie-app.com/pr4h5V9snnqa1
Also the way it deals with the boundaries is very consistent with the other non-pure things you'll have to deal with so once you've learned the pattern it's smooth sailing across Elm
If you're interested in D3 maybe check out https://github.com/gampleman/elm-visualization which takes a lot of the same ideas.
D3 is also not plain sailing when it comes to JS -> JS integration as it wants to control state and the DOM so if you're using another framework you end up trying to cobble together your own protocol for dealing with the boundaries.
https://www.youtube.com/watch?v=zXBdNDnqV2Q Shirley Wu is the expert.
3
u/invisipunk Nov 08 '23
Melange might be worth looking at: https://melange.re/v2.1.0/communicate-with-javascript/
3
u/flummox1234 Nov 09 '23
Elixir
4
u/x-0-y-0 Nov 07 '23
Scalajs
4
u/[deleted] Nov 07 '23
JavaScript
2
u/ianffcs Nov 08 '23
Clojurescript
2
u/fbn_ Nov 09 '23
gleam
2
u/EffectiveMidnight438 Nov 11 '23
Take a look at Fulcro (https://github.com/fulcrologic/fulcro), which is an excellent batteries-included, but flexible, ClojureScript library for building SPAs.
2
u/kierans777 Nov 21 '23
I do all my JS FP using Crocks. Crocks has helpers to integrate pure code with impure code so that you can wrap libraries pretty easily. For example using the
tryCatchfunction wraps exception throwing code to return aResultfrom the function.2
u/ColorOfTheFire Nov 08 '23
Can you not write three, D3 and p5 functionally? I know the examples might not be FP but they're all js libraries after all?