kach / memo

A language for mental models
https://pypi.org/project/memo-lang/
28 stars 1 forks source link

more ergonomic way to return posterior (E[speaker.n == n]…) #60

Open kach opened 1 month ago

chentoast commented 1 month ago

what about having a magic posterior variable that can only be used in return statements?

something like:

@memo
def f():
    cast: [alice]
    alice: chooses(x in X, wpp=1)
    return posterior[alice.x]
kach commented 1 month ago

I like it. What if it was in the header?

@memo
def f[alice.x]():
  cast: [alice]
  alice: chooses(x in X, wpp=1)
  return
chentoast commented 1 month ago

i think i'm not as big a fan of that for three reasons

  1. it might be confusing to mix "forall" and "return" properties in the same place, i.e. f[x: X, alice.x](): looks weird.
  2. it also feels backwards in terms of reading flow. Why is alice.x at the top of the function when I as a reader don't even know what it is yet?
  3. It's kind of confusing from a regular PL perspective to have a function return something even though it has an empty return statement
kach commented 1 month ago

Hmm, true, but I think it's important that it is specified somewhere in the header. I want the header to exactly reflect the shape of the returned tensor. Maybe something like this?

@memo
def f[posterior]():
  cast: [alice]
  alice: chooses(x in X, wpp=1)
  return alice.x