tweag / HaskellR

The full power of R in Haskell.

Home Page:https://tweag.github.io/HaskellR

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't make toplevel bindings?

Hodapp87 opened this issue · comments

This is from latest git master, built with the "From Github" instructions of https://tweag.github.io/HaskellR/docs/build-and-install.html. I am going through some of the tutorials, such as https://tweag.github.io/HaskellR/docs/using-h.html. First thing I run into:

$ stack --docker exec H
Prelude H.Prelude> H.printQuote [r| x <- 1 |]

<interactive>:2:1: Not in scope: ‘H.printQuote’
Prelude H.Prelude> import qualified H.Prelude.Interactive as H
Prelude H.Prelude H> H.printQuote [r| x <- 1 |]

<interactive>:4:1: Warning:
    In the use of ‘printQuote’ (imported from H.Prelude.Interactive):
    Deprecated: "Use 'p' instead."
[1] 1
Prelude H.Prelude H>

I had thought that H was supposed to have everything included for interactive use, and so it should be including H.Prelude.Interactive or at a minimum the docs should say something about this.

This is just an annoyance, though, because the real issue is what I run when copying the second example from https://tweag.github.io/HaskellR/docs/evaluating-r-expressions.html:

Prelude H.Prelude H> H.p [r| x <- 1; x + 2 |]
[1] 3
Prelude H.Prelude H> H.p [r| x |]
*** Exception: R Runtime Error: Error in (function ()  : object 'x' not found

I run into this in Jupyter too when loading https://github.com/tweag/HaskellR/blob/master/IHaskell/examples/tutorial-ihaskell-inline-r.ipynb and clicking Cell / Run All (or just stepping through one cell at a time):

toplevel

For some reason the given examples which are supposed to make toplevel bindings don't seem to work in either case.

Update: I just found via 'git bisect' that this is occurred with 5acaf13 and then quickly saw:

One consequence of this patch is that assignments no longer have global
scope. This is a feature: it protects against effects of R's late
binding in pure quasiquotes. To get the same effect as before one has to
use the `<<-` operator. Which unlike `<-`, will conveniently fail if you
try to redefine a "locked" binding, which applies to all functions
defined in a package somewhere.

This was noted in inline-r/CHANGELOG.md, but this somehow didn't make it into the docs.

I did a pull request on the tutorial notebook. I have no idea where the source is for https://tweag.github.io/HaskellR/docs/using-h.html or other pages that have examples that will fail, or else I'd fix them myself.

The release version of H and inline-r should work as advertized in the docs. The issue is that the website only documents the latest release, but not prior releases nor future releases. So if you're living on the bleeding edge, i.e. master, then you may come across the occasional inconsistency.

The issue addressed by #244 is a real bug in the IHaskell tutorial though. Really thought I fixed that already but clearly not.