Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a DAG interface #25

Open
thufschmitt opened this issue Jan 26, 2023 · 0 comments
Open

Provide a DAG interface #25

thufschmitt opened this issue Jan 26, 2023 · 0 comments

Comments

@thufschmitt
Copy link
Member

A number of things in the final environment are lists, and lists don't compose well (they don't compose at all currently in Nickel, and that's arguably the less bad solution). As a consequence, we'll likely want to internally represent them as DAGs. Defining a DAG is easy (see below), but fairly verbose to use.

With a smart contract (no pun intended), we could probably make this much lighter by just normalizing the fields that we pass in.

let
    DagElement = fun Data => {
            before : Array Str | default = [],
            after : Array Str | default = [],
            value : Data
        }
in let
    Dag = fun Data => {
        _: DagElement Data
    }
in
let
  # FIXME: This isn't sorting anything, would have to
  topo_sort | Dag Str -> Array Str = fun dag => array.map (fun elt => elt.value) (record.values dag)
in
let StructuredEnvVar = { sep : Str | default = ":", elems : Dag Str } in
let StructuredEnv = { _ : StructuredEnvVar } in
let Env = { _ : Str } in
let destructure_env_elt | Str -> StructuredEnvVar -> Str = fun name { sep, elems } => string.join sep (topo_sort elems) in
let destructure_env | StructuredEnv -> Env = fun env => record.map destructure_env_elt env in
{
    env | Env = destructure_env structured_env,

    # Building the DAG in client code. This is so nice because it composes well,
    # but it's also quite heavy to write
    structured_env | StructuredEnv = {
      PATH.elems = {
        bash.value = "$bash/bin",
        gcc.value = "$gcc/bin",
        clang.value = "$clang/bin",
        clang.before = ["gcc"],
      },
    },

    # Would be nice to be able to just write (for the simple cases)
    # something like
    # ```
    # structured_env.PATH = [ "$bash/bin", "$clang/bin", "$gcc/bin" ],
    # ```
    # which would expand to
    # ```
    # Structured_env.PATH.elems = {
    #  "$bash/bin" = { value = "$bash/bin", before = ["$clang/bin"], },
    #  "$clang/bin" = { value = "$clang/bin", before = ["$gcc/bin"], },
    #  "$gcc/bin" = { value = "$gcc/bin", },
    # },
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant