Skip to content

Commit

Permalink
Add language specialization example in R
Browse files Browse the repository at this point in the history
  • Loading branch information
arendsee committed Feb 19, 2018
1 parent 5f9855b commit 027b2d3
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/types/by-language/types.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,33 @@ f <- function(x) x + 1
f <- function(x){
colSums(x)
}


## Two different language specific specializations of Table
#-- RDataFrame ::
#-- lang "R"
#-- cast_as "data.frame"
#-- is_a Table
#-- RDataTable ::
#-- lang "R"
#-- cast_as "data.table"
#-- import "data.table"
#-- is_a Table

## Define the casting function
#-- as.data.table :: role "cast" => RDataFrame a -> RDataTable a
#-- as.data.frame :: role "cast" => RDataTable a -> RDataFrame a

## Finite set of symbols (Enum) but encoded in R as a string (rather than the
## default, a factor). We avoid the issues of handling factors, but retain the
## semantic information.
#-- RStringFactor ::
#-- lang "R"
#-- cast_as "character"
#-- is_a Enum

#-- foo :: RDataFrame {a:Integer; b:String; c:RStringFactor (Cat, Dog, Eel)} ->
#-- RDataFrame {a:Integer; b:String}
foo <- function(x){
subset(x, c == "Eel")[-3]
}

0 comments on commit 027b2d3

Please sign in to comment.