Which language to embed in Haskell

(cross-posted from reddit
I know the question has already been asked here, but it was a few years ago, I wonder if the situation has changed, so I ask again.

I need to add scripting capabilities to one my software, i.e. give the user the possibility to write it’s own “script” and have the program execute it. Ideally, being able to write such a script as an Haskell EDSL would have been great but I don’t think it is possible (or easy). So before rolling out my own language, I was wandering what are the best options ?

3 Likes

Lua of course!

8 Likes

I was hoping for something more exciting than Lua but I guess that’s the best I’ll get. I might add a preprocessing stage to make syntax more “specific”.

GNU project uses Scheme as a scripting language.

2 Likes

Scheme is a bit too exciting lol. However is there any (maintained) Haskell binding to scheme ?

that was my first approach to FP! then came Lisp. then I found Hs and had to ditch macros for types :man_shrugging:

2 Likes

I think your question is a bit open ended. There are quite a lot of languages that can be embedded in Haskell. If you add some preferences and list what you’ve already looked at, you might get additional responses.

2 Likes

I might have not been clear. By embedded I mean something that can be read and evaluated at runtime and call things from the software.

This is part of a warehouse management software. At the moment, a warehouse is described by a set of csv, one with the list of the shelves (name and dimensions) list of boxes (name and dimensions) and list of actions (which are mainly moves those boxes to those shelves, or tag those boxes with this tags and moves the boxes with T to shelves with tags S. etc …)

Now the needs are getting much more complex, I need to be able to express things like, “create a slot for every (product) colors available and if there are free space in the allocated shelves, create extra slots for the best selling colors”, or “fill the shelves in column (going up first) but make sure a column correspond to only one variant”. etc …

At the moment, all of that is possible (just using csv files) but it is becoming a nighmare to maintain, thus the use of specific DSL.
I am the developer and the main user, so the DSL can be(pretty much) as complicated as I want, but it need to be interpreted at runtime (without having to recompile and restart the server every time I make a change to the script).

1 Like

ha :grinning_face_with_smiling_eyes:

6 Likes

Have you looked at Dhall?

2 Likes

Would it make sense to consider using an off the shelf database which you can just access from a separate process/machine? That way you could also avoid recompiling the main management application.

There is definitely some truth there, however hardcoding (and therefore redeploying every five minutes is not an option). The irony is that it started as a hardcoded Haskell DSL.

A database is good to store and eventually inspect the state of the warehouse but not good enough to “describe” filling strategies. Part of the problem is this is a real world warehouse and we have to deal with the fact that some boxes might be where they shouldn’t , boxes might not be sorted as they should but we don’t have the resources to resort them physically, the suppliers send same products in boxes of a different sizes without warning us etc . In way the warehouse is a mess, but we know (the computer) where every boxes is.

That could be an option. As I am only using csv file at the moment, it probably would be possible to have Dahll representing some csv. That will allows to have some kind of macros and simple mathematics.
Unfortunately I understand in Dahll you’ll have to quote every string which means pretty much everything.
I see that as a deal breaker …

1 Like

I mean if you have a separate database then you can just write your strategies in your old EDSL in Haskell and compile and run it as a separate program from the main management application that just accesses the database concurrently.

Maybe my choice of the word “strategy” is wrong.
What I mean is for example. We are getting a new delivery at the beginning of January.
The warehouse is as it is (we’ve scanned the boxes and their positions) so the system knows it.
What we have to do know is decide in advance where each incoming boxes will go.

Most of the time it’s straight forward, all the new boxes of a given style (lets’ call it T-Shirt) go in the shelf containing the old boxes of the same style (lest call it S1). Depending on the number of boxes we can just drop them next to the old one, we write

    T-Shirt, S1

In that case you have the old box on the left of the shelf and the new one on the right. Boxes are sorted by batch.
Or we want to take all the old boxes out sort them aphabetically with the new one and refill the full shelf. This is written

   T-Shirt, @S1

Now all the boxes are sorted alphatically by color, black T-shirt first, then blue the reds regardless of the batch.

@ means resort the new boxs with boxes already present in the shelf.
Or it might be that too many boxes are coming and we need to put some in anoher shelf (S2). There are again differet way to do it.If I don’t care I just write

  T-Shirt, S1 | S2

And the system will put what it can in S1 and then in S2. But S2 might be too high to be reached so I would prefer to have at least one box per color in S1, So I’ll write

  T-Shirt^1, S1
  T-Shirt/!S1, S1|S2

The first line move the 1 box per color to the shelf S1 The 2nd line move every T-Shirt which are not in S1 in S1 or S2.

Then I might realize that we have too many color to fit in one shelf. I need to find if there is somewhere another shelf which will accommodate the all the colors and find where to move the content of this new shelf.
But that’ only the beginning, things get much much more complicated than that.

So basically, we have a virtual warehouse when can move boxes and try things until we are happy with the result and I want to replace this simple language (select box, select shelf, move selected boxes to selected shelves) by a scripting language.

1 Like

I remember that Facebook managed to hot-swap parts of their Sigma spam fighting system, there is a blog post about it as well as code samples and a Haskell package. Hence you may get away with just using Haskell as scripting language. Haven’t tried it myself, though.
We’ve been using an interpreted scripting language at work for controlling machinery and it is a pain to develop in. So you should be thankful for every static guarantee that a compiler can give you.

1 Like

Hey, I used to work for a company* that successfully used its own DSL for a loooong time and still does. Surely if one company can do it every company can do it, right!? Also, I feel like most of the problems described in this blog don’t really apply if you’re using {existing scripting language} and interpreting it through {existing scripting engine} rather than running your own stuff. I support the Lua suggestion for that reason :slight_smile:

*McMain. If anyone here is running a giant operation on the side and want maintenance software for it, consider this me plugging them. Tell them Hassan send you.

1 Like

How about dhall with a custom pre-processing parser to handle whatever nicer syntax you want to add for your domain? :slight_smile:

Was anyone else half-expecting this post to end with:

For the example input, the first shelf to exceed its capacity is S2, after the warehouse accepts 105 boxes.

Using your warehouse filling strategy, what is the maximum number of boxes the warehouse can accept without exceeding the capacity of any shelf?

1 Like

Sorry but I dont understand what you mean.