Code Monkey home page Code Monkey logo

accelerated's Introduction

acceleRated

Why not?

Discussions

Functions

Functions are defined to ease the use of other modules.

Typing

Types are defined primarily so that functions can check and manipulate their arguments. Often, these checks and coercions may be complex, and also may need to be performed many times for different functions exposed as an API, or even internally. R has a highly usable type system in S3/S4, but constructing these classes can be cumbersome for small functions, and if not used intelligently, can use up more time or memory than necessary in repeated construction. Implementing the desired type system through classes would be redundant.

We would like the ability to "tag" values with types, but for this to not take up any space at runtime. Luckily, R has a fantastic metaprogramming interface. We will allow values to be declared with a type in an environment, and with metaprogramming magic, these types can bubble up to delegating functions, if they also use this type system. Types can be composed, and variables declared with types resolve to their actual values at runtime.

Example:

newtype(degree, double, explicit_coercions = TRUE)
newtype(radian, double, explicit_coercions = TRUE)
coercion(degree, radian, _ / 180.0 * pi) # uses single-arg anonymous function syntax
coercion(radian, degree, _ / pi * 180.0)

newtype(trigResult, and(double, between(-1, 1)))
safe_sin <- (trigResult <- radian) %f% sin(_)

theta <- typed(and(double, nonNegative), 3.14)
print(safe_sin(theta)) # prints something close to 0
print(safe_sin(radian(1.5))) # prints something close to 1
print(safe_sin(1.5)) # error; need explicit coercion
print(safe_sin(radian(""))) # error; incompatible types

# argument to safe_sin doesn't need to be coerced, because its type is declared
some_math <- (double <- radian) %f% 2 * safe_sin(_)

LICENSE

GPL 3.0+

accelerated's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.