Skip to content

Instantly share code, notes, and snippets.

@okram
Last active September 1, 2020 00:25
Show Gist options
  • Save okram/fc775a28944397d7f22c138b851c4680 to your computer and use it in GitHub Desktop.
Save okram/fc775a28944397d7f22c138b851c4680 to your computer and use it in GitHub Desktop.
// the social.mm model-ADT is something I plan to build up to be the primary model used for the documentation.
// nat -- natural positive integer
// date -- 3 element list month/day/year
// moday -- 2 element list with a default year provided
// person -- a person has an id, name, and age.
// badge -- a badge has an id-code and a date
social:('type' -> (nat -> (nat<=int[is,bool<=int[gt,0]]),
date -> (date:(nat<=nat[is=<12];nat<=nat[is=<31];nat),
date<=(nat<=nat[is=<12];nat<=nat[is=<31])[put,2,2009]),
moday -> (moday<=int-<(int;int)),
person -> (person:('id'->int,'name'->str,'age'->nat),
person<=int-<('id'->_,'name'->'anon','age'->1)),
badge -> (badge:('code'->int,'date'->date),
badge<=int-<('code'->_,'date'->date))))
// NOTE: Everything that is not a value is a "type".
// name:obj is a single-instruction type ("a data structure")
// name<=obj is a multi-instruction type ("a function")
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
~/software/mmadt/vm/jvm$ bin/mmadt.sh
_____ _______
/\ | __ |__ __|
_ __ ___ _ __ ___ _____ / \ | | | | | |
| '_ ` _ \| '_ ` _ |_____/ /\ \| | | | | |
| | | | | | | | | | | / ____ \ |__| | | |
|_| |_| |_|_| |_| |_| /_/ \_\____/ |_|
mm-adt.org
mmlang> :[model,'data/model/social.mm'] // put the model instructions at the root of the obj graph
mmlang> 5 => nat // turn int 5 into a nat
==>nat:5
mmlang> 5 ~> nat // ~> is the paths from int-to-nat
==>((int;nat))<=5[walk,nat]
mmlang> 5 ~> date // there are 2 ways to get from int-to-date
==>((int;nat;int;moday;date),(int;moday;date))<=5[walk,date] // you get back a group of monoids (a monoid ring)
// ,-group (+) are parallel idependent paths
// ;-monoid (*) is serial dependent steps
mmlang> 5[split,[walk,date].0] // take the first path (-< is [split])
==>(5;nat:5;5;moday:(5;5);date:(5;5;2009))
mmlang> 5[split,[walk,date].1] // take the second path
==>(5;moday:(5;5);date:(5;5;2009))
mmlang> 5[split,[walk,date].0]>- // homomorphism from lifted poly back down to obj
==>date:(5;5;2009) // poly can 'lift' the obj graph for intropection
// merge (>-) evaluates the poly according to its algebra (which is tied to SRT)
mmlang> 5[split,[walk,date].1]>- // both int-to-date paths yield the same result (commuting)
==>date:(5;5;2009)
// below are a collection of => mappings between types
// the style mm-ADT is trying to advocate is that the developer is very aware of the obj graph.
// they know they are at a value whose type is connected to other types via models.
// when they want to look at their data from a particular perspective, they =>
// kv => vertex => row => person => rec ... just morph between representations.
mmlang> 5 => badge
==>badge:('code'->5,'date'->date:(nat:5;nat:5;nat:2009))
mmlang> 5 => person
==>person:('id'->5,'name'->'anon','age'->nat:1)
mmlang> 5 => date
==>date:(nat:5;nat:5;2009)
mmlang> 5 => moday
==>moday:(5;5)
mmlang> 5 => moday => date
==>date:(nat:5;nat:5;nat:2009)
mmlang> 5 => moday => date.2
==>nat:2009
mmlang> 5 => moday => date.2 => person
==>person:('id'->2009,'name'->'anon','age'->nat:1)
mmlang>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment