Skip to content

Instantly share code, notes, and snippets.

@pekhee
Last active March 27, 2017 20:06
Show Gist options
  • Save pekhee/34831d04104074e3400b59594b8c8223 to your computer and use it in GitHub Desktop.
Save pekhee/34831d04104074e3400b59594b8c8223 to your computer and use it in GitHub Desktop.
Potential syntax for rish

What is a Category

Imagine it as a more generic version of class in OOP.

A collection of objects and arrows. Objects are things. Arrows take objects and return objects in the same category.

You can imagine a class in OOP as a category, its instances as objects and its methods as arrows. A category doesn't have to have objects of same type. Arrows can work on a subset of objects. We can write functions to modify both objects and arrows. We can move an object or arrow from a category to another one.

What is a Functor

A function from one category to another one. Functors may lose information but they preserve the essence of categories.

For example a functor from Array to Set loses ordering and duplicates but these information aren't useful in a Set. A functor from Array to Array can lose the ordering without compromising what we can do with an array.

What is a Monad

A pair of adjoint functors composed together.

For example we have two functors

  • A: JSON -> Array
  • B: Array -> JSON If we compose these two together we get a functor from JSON to itself. This functor goes from JSON to Array and back. Since it does that it can let us work on the array to modify json.

A Monad takes us from a category to another one and back. This means we can warp ourself to any other category that we have a Monad for, do whatever we want in that category and observe the results in our current category.

  • Upper case identifiers are type classes. > is bind.
  • Id> is equivelant to :|(Id) > func |:
  • :| and |: are adjoint functors. From an arbitrary category to array and back.
  • :|(Id) is a functor from current type to Id.
  • | is an infix operator identical to filp (.) aka left compose.
  • Lines before --- are raw data injected into code.
  • &Id makes every line start with Id >
DEPS: libsmt, smt
COMPILE:"""
# Input LIBSMT_PATH, SMT_PATH
compile
"""
KEEP:"""
# Input KEEP_PATH
cp * $KEEP_PATH
"""
EXPOSE:"""
# Input EXPOSE_PATH
cp $KEEP_PATH/bin/* $EXPOSE_PATH/
cp $KEEP_PATH/*.so $EXPOSE_PATH
"""
---
&Package
deps = require DEPS
files = default_build_and_expose deps, COMPILE, KEEP, EXPOSE
return $ package files
#!/usr/bin/env rish
selected_nodes = Node > all :| filter _.tag == "deploy" | filter _.mem > 1000 |:
image = Package > from_git "git://example.com:example.git" Git> ignore Git> head > deps_from "DepFile"
network = selected_nodes :|(Network) new > expose (_.edge?) 80, 443 > route 443, 80 > eliminate_https gen_ssl_cert
deployment = selected_nodes :|(RollingDeployment) > deploy image > migrate > attach network
deployment :|(Monitor) on_socket listen_socket > run "./bin/smt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment