Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for a functional language based on YAML

I am looking for a language that mixes data description (a la YAML or JSON) with basic scripting capabilities (e.g. variables, conditional expressions, callback functions). Something that describes a hierarchical structure of lists & maps like YAML, but where the leaf values are functions rather than literal data.

Up until now I've been approaching this by adding expression logic on top of YAML. This lets me build on existing parsers, but it also leads to really awkward syntax and I have to implement the compiler/interpreter aspect of it myself. I don't think I'm competent to do that.

An alternative is to adopt some subset of an existing language so that I can build off a real compiler. Sadly I'm not well versed in any functional programming languages. I honestly don't know where to start with this.

Can anyone suggest a functional language that has some or all of these properties:

compact syntax for expressing hierarchical lists and maps
pure functional
lexical scoping
no OOP (using maps rather than static compound types)
first class functions (primary data structures will be lists/maps of functions)
type inference
compilable from an AST (if I have to write my own parser)
compilable to JVM bytecode (it would make my life a lot easier)

Scala is an obvious choice since it targets the JVM, but for all I know there might be something out there closer to what I need. Any suggestions?

like image 268
UnquietTinkerer Avatar asked Feb 02 '26 06:02

UnquietTinkerer


2 Answers

Clojure is the best fit.

  • Compact syntax for maps and lists - Yes
  • Pure functional - Not as pure as Haskell, but functional enough
  • Lexical scoping - Yes
  • No OOP - This is the preferred architecture when starting a codebase from scratch
  • First class functions - Yes
  • Type inference - dynamic type system with support for type hints
  • Compilable from an AST - Clojure syntax is almost an AST to begin with
  • Compilable to JVM bytecode - Yes

I think it is a better fit than Scala for these reasons:

  • More functional and less of an object oriented style
  • More compact syntax for maps and lists
  • Syntax is closer to an AST and is easier to parse
like image 177
dbyrne Avatar answered Feb 05 '26 03:02

dbyrne


This is an interesting use case. It sounds a bit like Common Workflow Language which is described in YAML and is used to construct computation graphs

like image 39
Kaushik Ghose Avatar answered Feb 05 '26 05:02

Kaushik Ghose