Giter Club home page Giter Club logo

kongware / scriptum Goto Github PK

View Code? Open in Web Editor NEW
381.0 15.0 21.0 5.08 MB

Functional Programming Unorthodoxly Adjusted to Client-/Server-side Javascript

License: MIT License

JavaScript 100.00%
functional-programming polymorphism algebraic-data-types sum-types tagged-unions pure-function monad recursion javascript composition function-composition point-free folding transducers purity corecursion catamorphism anamorphism monad-transformers lazyness

scriptum's Introduction

      ___           ___           ___                        ___          ___           ___           ___     
     /\  \         /\  \         /\  \          ___         /\  \        /\  \         /\__\         /\__\    
    /::\  \       /::\  \       /::\  \        /\  \       /::\  \       \:\  \       /:/  /        /::|  |   
   /:/\ \  \     /:/\:\  \     /:/\:\  \       \:\  \     /:/\:\  \       \:\  \     /:/  /        /:|:|  |   
  _\:\~\ \  \   /:/  \:\  \   /::\~\:\  \      /::\__\   /::\~\:\  \      /::\  \   /:/  /  ___   /:/|:|__|__ 
 /\ \:\ \ \__\ /:/__/ \:\__\ /:/\:\ \:\__\  __/:/\/__/  /:/\:\ \:\__\    /:/\:\__\ /:/__/  /\__\ /:/ |::::\__\
 \:\ \:\ \/__/ \:\  \  \/__/ \/_|::\/:/  / /\/:/  /    /:/  \:\/:/  /   /:/  \/__/ \:\  \ /:/  / \/__/~~/:/  /
  \:\ \:\__\    \:\  \          |:|::/  /  \::/__/    /:/  / \::/  /   /:/  /       \:\  /:/  /        /:/  / 
   \:\/:/  /     \:\  \         |:|\/__/    \:\__\   /:/  /   \/__/   /:/  /         \:\/:/  /        /:/  /  
    \::/  /       \:\__\        |:|  |       \/__/   \/__/            \/__/           \::/  /        /:/  /   
     \/__/         \/__/         \|__|                                                 \/__/         \/__/    

Functional Programming Unorthodoxly Adjusted to Client-/Server-side Javascript

scriptum, a functional standard library.

There are three categories of effects:

  • mutations
  • input/output
  • control flow

scriptum handles these three categories using the following concepts:

  • tree-based persistent data structures (mutations)
  • continuation types optimized for serial/parallel asynchronous processing (I/O)
  • continuation type optimized for synchronous processing (control flow)

Since I/O is asynchronous in Javascript/Node.js, the first iteration of the event loop is pure in terms of interacting with the real world. It is thus possible in the context of the event loop to implement the pure core imperative shell design pattern provided the following two requirements are met by asynchronous types:

  • they are lazy
  • they are stateless

While the native Promise type misses both criteria, scriptum's Serial and Parallel types are compliant.

Control flow comprises the following instances:

  • short circuiting
  • indeterminism (0..n iterations of evaluation)

Features:

  • persistent data structures based on 2-3 trees
  • lazy evaluation with implicit/explicit thunks
  • principled, purely functional async computation (serial/parallel)
  • stack safe recursion (tail recursion, modulo cons, monad recursion)
  • reification control flow using CPS and the Cont type
  • product and variant types
  • simple pattern matching
  • functional Iterator machinery
  • functional iterator type idempotent in its next method
  • reactive programming with event streams and behaviors
  • DequeMap, a doubly-ended queue based on a native map
  • MultiMap to encode 1:m key/value relations
  • lots of predefined type class definitions
  • lots of predefined polymorphic functions
  • lots of functor, applicative and monad definitions
  • dynamic functorial fusion using yoneda
  • static loop fusion using transducers
  • flat composition syntax using infix
  • memoization of recursive functions
  • functional optics
  • parser combinators
  • functor composition
  • let expressions
  • recursion schemes
  • delimited continuations
  • coroutines
  • tracked functions
  • and much more..

Status

unstable

Obsolete projects:

Future Studies

  • probabilistic data structures
  • fuzzy logic and encoding uncertainty
  • separation of command and query model + event sourcing (CQRS/ES)
  • software transaction memory (STM)
  • strong eventual consistency (CRDTs)
  • distributed applications

scriptum's People

Contributors

atomrc avatar drmats avatar galnir avatar ivenmarquardt avatar lukejewers avatar meereenee avatar monotykamary avatar poorlydefinedbehaviour avatar sdghbtn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scriptum's Issues

Left/Right biased Semigroup instances for Either

Consider left-biased (error propagating) and right-biased (error fixing) instances for Either. This would require distinct types. What would be meaningful names for their type and value constructors?

How to share intermediate results of async computations?

Say there is a Task foo and I want to reuse foo's result several times. The problem with Task is that it is based on continuations (CPS) and thus lazily evaluated. So every time I call foo.runTask(res, rej) the computation is reevaluated instead of simply returning the result.

There seems no way to allow for sharing foo's result, even not with an impure solution. The only way I can think of is to be in the right scope:

const foo = fileRead("utf8") ("./foo.txt");

foo.runTask(s => {
  // in this scope we can reuse s as often we want
}, id);

This is not satisfying, of course. Maybe someone will come up with a better solution.

Obtain foldWhile semantics by additionally passing the current index

By additionally passing the current index we can prematurely break out of a fold of an indexed compisite type::

const strFold = alg => zero => s => {
  let acc = zero;

  for (let i = 0; i < s.length; i++)
    [acc, i] = alg(acc) (s, i);

  return acc;
};

or we can skip certain iterations. I think this approach is superior to indicate the premature break with a special type, as I've done so far.

Add a bunch of useful array combinators

namely...

  • arrDiff/arrDiffBy
  • arrDiffl/arrDiffr
  • arrIntersect/arrIntersectBy
  • arrUnion/arrUnionBy
  • arrMapAccum
  • arrGroupBy
  • arrFindBy/arrFindIndexBy
  • arrCountBy
  • arrFindBy
  • arrFindIndex
  • arrFindIndexBy
  • arrFindLastBy
  • arrFindLastIndex
  • arrFindLastIndexBy
  • arrFindNthBy
  • arrFindNthIndex
  • arrFindNthIndexBy

Replace typeclasses with multimethods

I think multimethods are a more natural approach to allow function overloading for dynamically typed languages than typeclasses. Provided I've considered all aspects I will probably replace typeclasses.

multimethods must have the following properties:

  • they must be closed
  • they must support dynamic dispatch for one or more arguments
  • methods must be individually addable one at a time
  • dispatch values must be of any type (not just Strings)
  • dispatch value/method tuples must be of type (a, a -> b)/(a, b, a -> b -> c)
  • the dispatcher should always be uncurried for performance reasons
  • multimethods should accept either curried/uncurried methods

As opposed to typeclasses multimethods cannot express return type polymorphism, because without a value you cannot introspect a type.

Lens combinators are broken

lensGet et al. shouldn't leak the information whether they depend on Cont or Id internally. Additionally, these combinators need to be parameterized over the Lens type (objLens, arrLens etc.), so that they are ad-hoc polymorphic in this regard.

What should a file system related function return if it returns no data?

I mean functions like fileCopy or fileUnlink. For the time being they just return None (from Option), They should return someting IO related, though. scriptum uses Task for asynchronous and Effect for synchronous IO. So just Task((res, rej) => res(None)) for the former and Effect(() => None) for the latter? Would that be an improvement?

Add a Lens type for destructive updates

Since local mutations are not harmful but reasonable in a language without native persistent data types and structural sharing this seems to be a useful endeavor.

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.