Skip to content

Instantly share code, notes, and snippets.

@criloz
Last active September 15, 2019 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save criloz/dc9b9da9c56d47330eeb911acc0f4a09 to your computer and use it in GitHub Desktop.
Save criloz/dc9b9da9c56d47330eeb911acc0f4a09 to your computer and use it in GitHub Desktop.
genesis::functor functor(functor):functor;
functor morphism(morphism):morphism
genesis::morphism (functor)=> morphism{
//calculate the categories of the domain and codomain and the weight of the edge is the functor.body
return genesis::spiral_graph.add_edge(from: functor.domain->category, to: functor.codomain->category, weight: (domain)=>{
const result = functor(domain);
//decorate the result with the category of the codomain
genesis::spiral_graph.add_category(functor.codomain->category, to: result)
})
}
functor category(category):category;
/// morph functor into a category when the domain, codomain and name of the functor are the same
morphism (functor)=> category{
if(functor.domain->str == functor.name) &&(functor.codomain->str == functor.name) && functor.body == ``) {
genesis::spiral_graph.add_category(functor.name)
}
}
/// morph ident into a category
morphism (ident)=> category{
create_category(ident.name)
set_ident_category(category)
}
//bitcoin morph to category category before be shallowed by the functor category
category bitcoin;
category dollar;
//the line 5 automatically decorate this to bitcoin
morphism (number)=> bitcoin {
return number
}
/// this is a decorator then it will create the subcategory #bitcoin number, or #number bitcoin, the compiler make sure that they always means the same
morphism (number)=> dollar {
return number
}
console.log(dollar(50)) //#dollar number(50)
console.log(bitcoin(50)) //#bitcoin number(50)
morphism (dollar)=> bitcoin {
return dollar.0 / 10'000
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment