Can Elm Repl process whole files, multiple modules, etc

I’m interested in warming up my Elm knowledge by completing a project that will process text files. It will have nothing to do with the web. I know that Node.js can do this, right? Does elm repl or is there some other integration with Node.js that would let me do this?

There is elm/file which you could use to get the content of a file and work with it.

Also I think there was some experiments in the community with running elm on node but IMHO this is not the intended use-case for Elm.


Every year there are some that do the Advent-of-Code puzzles with Elm which usually involves parsing a text-file but as far as I know most just paste the content of these puzzle-inputs as a string into a .elm file and work from there.


Personally I’d go to other languages/frameworks to work with files but I guess you could work it out.

(Not sure if this is ok for me to post it here - if not please let me know or remove it: If you want something like Elm and work directly on node you could try out PureScript - the basic syntax is very similar but the scope and type-system is somewhat bigger compared to Elm. I personally resonate very much with PS and would recommend it.)

1 Like

Yes you can do it with Node.js. Here is an example you can use as a starting point:

https://github.com/the-sett/elm-aws-codegen/blob/master/src/index.js

2 Likes

elm/file looks perfect. I started learning Haskell 12 years ago and used it for a few personal projects. When I came up with this web project idea I started with Purescript but abandoned it eventually. Apparently my general web and javascript knowledge was not enough to understand how to use Purescript to make web pages beyond the simplest things and the Purescript documentation was not great at the time. Elm is more appealing to me with my given level of knowledge. I tutor computer science, normally Java and C++, but I did an Elm project with one of my students a couple years ago and we loved it.

3 Likes

Yes that’s true - for beginners Elm is a much better choice.


Well if you already know Haskell it’s probably no big deal but yeah it assumes more “common” javascript/node knowledge and while the docs are IMHO pretty good in PS what’s often hard to find are the entry-points into frameworks.

One problem is probably that there are various front-end libraries in PS which vastly different concepts - it’s hard to choose but there are really a few gems in there.

If you want to take another look: I’d recommend Halogen - it’s similar to TheElmArchitecture in style but fully embraces components (which makes the involved types a bit scary at first).
Or if you already know some react then the react-bindings might be a good starting point also.

I really enjoy writing Elm but in some scenarios TEA and the way side-effects and FFI is handled is just a big source of boilerplate for me.
This is where PureScript really shines for me - also it is way easier to link your own libraries (locally or in some git-repo) into a PS project.

We’ve had good luck with elm-posix:

for processing files directly from the Linux command-line. However, for my team that was after already being very familiar with using Elm for conventional TEA / web development. I’m less sure that this would be a good way to build your Elm skills. But it is similar to what you were asking for.

3 Likes

I’ve also been using elm-posix for Advent of Code, as you can see with my setup & solutions advent_of_code/2021/lang-elm at main · wolfadex/advent_of_code · GitHub.

If you’d prefer a repl like experience, you could use REPL | Node.js v16.14.2 Documentation along with Elm’s Platform.worker.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.