Haskell >>= R %>% HaskellR!

Sigrid Keydana, Trivadis
2017/06/07

system("whoami")

 

  • Sigrid Keydana
  • bit of a contender for the max no. of career changes competition (not a Kaggle competition)
  • data scientist and machine learning expert at Trivadis
  • currently mostly specialising in Deep Learning
  • blog: http://recurrentnull.wordpress.com, twitter: @zkajdan
  • functional programming aficionada but not enough time

Ceci n'est pas une pipe

 

-- get sth from stdin and print "hello, <x>"

getLine >>= putStrLn . ("hello " ++)

 

# this would be it...

readline() %>% (function(name) paste0("hello ", name))

This is not a fancy way of writing purrr's compose function ...

 

-- find the max value of a list, take its logarithm and make it negative

dostuff xs = negate . log . maximum $ xs

 

# this is purrr compose

dostuff <- compose(function(x) -x, log, max)

Neither is this an alternative syntax for purrr's partial.

 

-- a function that adds 1 to its argument

plus1 = (+1)

 

# this would be purrr's partial

plus1 <- partial(`+`,1)

This is Haskell!

 

  • pure, strongly typed, lazily evaluated language
  • elegant code that reads just like a description of the algorithm itself
  • widely used in industry (financial and trading systems, real-time applications, metaprogramming, strongly parallelized systems, web applications, cryptography … etc. etc. etc.)

If Haskell's so great, what's the problem?

 

  • some things are very hard to do / not implemented: see State of the Haskell ecosystem (continuously updated)

    • Machine Learning
    • Data Science
    • Visualization
  • … right what R is great at!

Enter: HaskellR!

 

  • developed by Tweag I/O
  • embedded R interpreter (inline-r)
  • interactive prompt for evaluating Haskell as well as R code (H)
  • Jupyter notebook compatible (ihaskell-inline-r)

HaskellR in a nutshell

 

  • no marshalling/unmarshalling of arguments (R values are pointers to SEXPRECs as in R itself)
  • R capabilities provided by hosting an embedded instance of the R interpreter
  • everything R happens inside the R monad
  • between calls to the embedded R interpreter, state is preserved

Let's get this more concrete...

 

Demo time!

  • Intro to HaskellR demo
  • Stock market demo