Skip to content

Instantly share code, notes, and snippets.

View marcoonroad's full-sized avatar
🦋
the Future() has been CANCELLED and we .Restart() the DEAD Event[] from the past

Marco Aurélio da Silva marcoonroad

🦋
the Future() has been CANCELLED and we .Restart() the DEAD Event[] from the past
View GitHub Profile
@marcoonroad
marcoonroad / dependent.hs
Last active December 23, 2015 01:49
Attempt to encode dependently typed data structures in Haskell...
{-# LANGUAGE GADTs #-}
module Dependent (
Nat, O, S,
Z, Zero, SuccPos, SuccNeg,
Prop, V, X,
List, Nil, Cons,
Vector, Exist, Times,
Option, Some, None,
Coprod, OnLeft, OnRight,
@marcoonroad
marcoonroad / dependent-datastructs-example.v
Created December 21, 2015 19:49
A few dependently typed data structures in Coq.
Require Import Utf8.
Section Existence.
(* a simple list that says if a given element is inhabitant *)
Inductive exst { T } (x : T) : bool -> Type :=
| Here : exst x false -> exst x true
| There : T -> exst x true -> exst x true
| NoSuch : T -> exst x false -> exst x false
@marcoonroad
marcoonroad / option-test.lua
Last active August 29, 2015 14:27
lua's option monad implementation at its semantics (dynamic typing) and without static guarantees (data constructors, contracts, ...), but with the safely null-propagation.
-- begin of test --
local option = require 'option'
local hash = { a = 15, b = 2, c = 7 }
local list = { 4, 8, 2, 3 }
local function test (label)
local first = option.bind (hash[ label ])
local second = option.bind (list[ first ])
@marcoonroad
marcoonroad / ex2.v
Last active August 29, 2015 14:22
<Coq> Software Foundations exercise...
(*
Exercise: 2 stars (andb_eq_orb)
Prove the following theorem. (You may want to first prove a
subsidiary lemma or two. Alternatively, remember that you do not have
to introduce all hypotheses at the same time.)
Theorem andb_eq_orb : forall (b c : bool), (andb b c = orb b c) -> b = c.
*)
@marcoonroad
marcoonroad / Macros.h
Created May 24, 2015 04:04
Small OOP test on C...
#ifndef MACROSH
#define MACROSH
#define super(self) (& self -> __parent)
#define context(self) (self -> __hidden)
#define send(self, slot, ...) (self -> slot (self, ## __VA_ARGS__))
#define bless(type) malloc (sizeof (struct __##type##__))
#define method(type, name) __##name##__##type##__
#define as /* */
#define extends(type) struct __##type##__ __parent
@marcoonroad
marcoonroad / dynparent.lua
Created May 16, 2015 13:42
Dynamic inheritance example in Lua...
-- an exampleof "dynamic inheritance" --
-- changing lookup prototypes (parent objects) --
local Object = { }
-- primitive methods --
function Object : bless (struct) return setmetatable (struct, { __index = self }) end
function Object : clone ( )
@marcoonroad
marcoonroad / Failure.h
Last active August 29, 2015 14:21
Simple exception handling library with C...
#ifndef FAILUREH
# define FAILUREH
#include <setjmp.h>
static jmp_buf hook;
void raise (char * reason) {
longjmp (hook, (int) reason); // cast the address into a int number
}
@marcoonroad
marcoonroad / readonly.lua
Created March 29, 2015 20:50
Read-only tables with Lua...
-- readonly test --
local function readonly (hash)
return setmetatable ({ }, {
__index = hash,
__newindex = function (self, key, value)
if rawget (getmetatable (self).__index, key) then
key = tostring (key)
value = tostring (value)
return error ("Attempt to rewrite the field <" .. key .. "> with <" .. value .. "> on given hashtable...")
@marcoonroad
marcoonroad / DocLinks.md
Last active November 5, 2022 18:28
Links sobre documentações de algumas linguagens...
@marcoonroad
marcoonroad / fib-react.pl6
Created February 3, 2015 19:53
An infinite loop / recursive reactor using Reactive Programming with Perl6 ...
#!/usr/bin/perl6
use v6;
# reactive programming per se is turing complete?
# --------------[ y, x + y ]--------------
# | |
# | ------ |