hakaru icon indicating copy to clipboard operation
hakaru copied to clipboard

Need `import`

Open JacquesCarette opened this issue 7 years ago • 6 comments

PR #117 could be made better, and so would issue #96 if we had import working. There has been much discussion [but apparently never recorded here? Just in the mailing list?] about how to do this.

JacquesCarette avatar Nov 23 '17 01:11 JacquesCarette

From my own notes from chatting with @ccshan about this suggest whatever solution we have provide

  1. Capture-avoiding substitution

I don't know if that is the right term. Basically baz.hk should work.

# foo.hk
normal <~ uniform(0, 1)
# bar.hk
y = normal(0,1)
# baz.hk
import foo
import bar

x <~ y
return (x + normal)
  1. Changes to the grammar to distinguish declarations from expressions

zaxtax avatar Nov 28 '17 17:11 zaxtax

Isn't normal already defined, so that foo.hk should, rather than 'work', return an error? I would consider it a bug, not a feature, if this worked!

If you were to rename normal to something else (like say z), then I would indeed expect baz.hk to work.

However, I do agree that import should be reasonably hygienic. Certainly if foo.hk defined something like y = uniform(0,1), then baz.hk should fail upon import of bar. I'm ok with shadowing for let, but shadowing across files that becomes order-dependent is a bad idea.

JacquesCarette avatar Jan 18 '18 16:01 JacquesCarette

So something like foo.hk does give me an error, but the following is a perfectly valid program

def sin(x real):
    cos(x)
sin(5)

I think we are in broad agreement, but we should be very clear and precise about what properties we want and don't want the module system to obey.

zaxtax avatar Jan 18 '18 17:01 zaxtax

One property I would like is that we have some way to inline definitions in different files so the simplifier be able to work across those boundaries.

zaxtax avatar Jan 18 '18 17:01 zaxtax

Why does redefining sin work? Why is that a good thing? Doesn't that just lead to much debugging pain for very little gain?

I purposefully avoiding using the word module. If we want a module system, then we're going to need to spend quite a bit more effort on it - likely more than is currently available.

Nevertheless, I do think we are generally in agreement. Definitely agree that I want to be able to inline definitions from different files.

JacquesCarette avatar Jan 18 '18 17:01 JacquesCarette

Bumping to get feedback from @ccshan

zaxtax avatar May 29 '18 14:05 zaxtax