code.pyret.org icon indicating copy to clipboard operation
code.pyret.org copied to clipboard

my-gdrive imports don't preserve annotation bindings

Open elfprince13 opened this issue 9 years ago • 5 comments

I have a a file that uses definitions obtained using the following: import my-gdrive("streams.arr") as S

Any annotations using ::S.Stream result in an "Couldn't find the annotation named Stream in the annotations from S" error. But running the same code with a ::Stream binding in the REPL for streams.arr works just fine.

elfprince13 avatar Sep 12 '15 16:09 elfprince13

Does the providing file say "provide-types *"? That said, it still should be consistent on whether it works across definitions and interactions.

jpolitz avatar Sep 12 '15 16:09 jpolitz

Ah - missing the provide-types *. The REPL I was testing with was the one for streams.arr, not the file importing it. Is provide-types actually documented anywhere on Pyret.org?

elfprince13 avatar Sep 12 '15 19:09 elfprince13

After adding provide-types * I can use them with S.Stream using import my-gdrive("streams.arr") as S, but trying to import them explicitly withimport Stream from my-gdrive("streams.arr")` still results in "used as a type, but not defined as one" errors.

elfprince13 avatar Sep 12 '15 19:09 elfprince13

@jpolitz @blerner I don't know how to reproduce what @elfprince13 was saying here, so I can't tell if this is still an issue. Poking.

schanzer avatar Mar 17 '20 02:03 schanzer

I believe these were the source files I was using that provoked the issue, but I haven't looked at them (or Pyret) in years, so no idea how useful they will be.

streams.arr:

provide *
provide-types *

data Tuple<a,b>:
  |pair(first :: a,second :: b)
end

data Stream<a>:
  |s-empty with:
    append(self :: Stream<a>, other :: (-> Stream<a>)) -> Stream<a>:
      other()
    end,
    concat(self :: Stream<a>, other :: Stream<a>) -> Stream<a>:
      other
    end,
    force(self :: Stream<a>) -> List<a>:
      empty
    end,
    map<b>(self :: Stream<a>, f :: (a -> b)) -> Stream<b>:
      s-empty
    end,
    zip<b>(self :: Stream<a>, other :: Stream<b>) -> Stream<Tuple<a,b>>:
      s-empty
    end
  |s-link(first :: a, rest :: (-> Stream<a>)) with:
    append(self :: Stream<a>, other :: (-> Stream<a>)) -> Stream<a>:
      s-link(self.first,lam(): self.rest().append(other);)
    end,
    concat(self :: Stream<a>, other :: Stream<a>) -> Stream<a>:
       s-link(self.first,lam(): self.rest().concat(other);)
    end,
    force(self :: Stream<a>) -> List<a>:
      link(self.first,self.rest().force())
    end,
    map<b>(self :: Stream<a>, f :: (a -> b)) -> Stream<b>:
      s-link(f(self.first), lam(): self.rest().map(f);)
    end,
    zip<b>(self :: Stream<a>, other :: Stream<b>) -> Stream<Tuple<a,b>>:
      cases(Stream<b>) other:
        |s-empty => s-empty
        |s-link(o-first,o-rest) => s-link(pair(self.first,o-first), lam(): self.rest().zip(o-rest());)
      end
    end
sharing:
  _plus(self :: Stream<a>, other :: Stream<a>) -> Stream<a>:
    self.concat(other)
  end,
  
  # visual metaphor is composition, because there isn't much flexibility
  # in naming
  _times(self :: Stream<a>, other :: (-> Stream<a>)) -> Stream<a>:
    self.append(other)
  end
end

fun continually<a>(n :: a) -> Stream<a>:
  s-link(n,lam():continually(n);)
end


fun raw-array-to-stream<a>(ary :: RawArray<a>) -> Stream<a>:
  fun ary-to-stream-helper(shadow ary :: RawArray<a>, n) -> Stream<a>:
    if n == raw-array-length(ary):
      s-empty
    else:
      s-link(raw-array-get(ary, n), lam(): ary-to-stream-helper(ary, n + 1);)
    end
  end
  ary-to-stream-helper(ary, 0)
end

stream = {
  make: raw-array-to-stream
}

fib-streams.arr:

import Stream, s-empty, s-link, stream, continually from my-gdrive("streams.arr")

fun fibs_dirty():
  (s-link(0, lam():s-empty;) + s-link(1, lam():s-empty;)) * lam(): fibs_dirty().zip(fibs_dirty().rest()).map(lam(t): t.first + t.second;);
end

fibs_clean = lam():# -> Stream<Number>:
  fun loop(h :: Number, n :: Number):
    s-link(h,lam(): loop(n,h + n);)
  end
  loop(0,1)
end

elfprince13 avatar Mar 17 '20 14:03 elfprince13