Re: HaskellR

23 views
Skip to first unread message

Boespflug, Mathieu

unread,
Aug 17, 2016, 10:44:20 AM8/17/16
to Dominick Samperi, haskellr
Hi Dominic,

you can lift an arbitrary list literals to an R vector:

H> let xs =  Data.Vector.SEXP.toSEXP [1,2,3::Double] :: SEXP s 'Foreign.R.Real

This works, thanks to the -XOverloadedLists extension. Then, using hexp, you can have a "view" of this vector as a first class Haskell value:

H> case hexp xs of Real v -> v
fromList [1.0,2.0,3.0]

This v is of a vector type, as defined in Data.Vector.SEXP. It's equipped with a Show instance like all other vector types.

Best,

--
Mathieu Boespflug
Founder at http://tweag.io.

On 17 August 2016 at 07:43, Dominick Samperi <djsa...@gmail.com> wrote:
Hello Mathieu,

I have been playing with an old package named hR (written by Dylan
Simon) for years, on and off, and I was planning to release an update.
But with HaskellR/H there is little need for this.
The main difference in design philosophy is that hR tries to model R
structures on the Haskell
side, whereas HaskellR works in terms of SEXP's and let's R take care
of the AST's
(for efficiency).

While the H interface is very nice, I'm trying to work at a slightly
lower level so that I can
view the AST corresponding to a SEXP using the viewer hexp (as
advertised in your docs).

By browsing through inline-r/tests/Test/Vector.hs, the closest I have
been able to come to this
is (in ghci):

myvec = V.toSEXP (V.fromList [1..3::Double]) :: R.SEXP s 'R.Real

:t hexp myvec

ghci tells me that the type is HExp s 'R.Real, and there is no
corresponding Show, so I'm not sure what you mean by viewier?

Based on your docs what I'm looking for is the ability to create a
SEXP pointing to
an arbitrary R data type, and view this datatype as an HEXP on the Haskell side.

Is there any sample code that you can point me to that shows how to
use the viewer, and how to compute on R AST's in Haskell?

Thanks,
Dominick

Reply all
Reply to author
Forward
0 new messages