NetworkVerification / nv

A Framework for Modeling and Analyzing Network Configurations
MIT License
31 stars 2 forks source link

Allow arbitrary function declaration order #39

Closed alberdingk-thijm closed 3 years ago

alberdingk-thijm commented 4 years ago

Right now, nv expects users to define anything they reference before it is called. The following code snippet does not compile:


let merge n x y = min x y

let min x y = if x < y then x else y

It would be convenient if nv could instead allow its top-level declarations in arbitrary order, as many other modern languages do.

One possible way of allowing this might be to topologically sort the declarations after parsing. If a cycle occurs due to 2 or more functions depending on each other, then an error can be thrown.

DKLoehr commented 4 years ago

A topsort seems like a good solution. It gets around the problem of accidentally introducing recursion into the language.

Probably related to #33 since this is something we'll want to consider when doing modules.