Skip to content

Instantly share code, notes, and snippets.

@Superstar64
Superstar64 / Combinator.hs
Last active May 19, 2023 19:23
Lazy parser combinators in Haskell
module Combinator where
{-
mnemonics:
pos : position
str : string
err : error
-}
import Control.Applicative (Alternative, empty, many, (<|>))
@Superstar64
Superstar64 / ast.cpp
Created April 4, 2022 22:54
Covariant shared pointers for abstract syntax trees
#include <cstddef>
#include <string>
#include <type_traits>
template <class Object> class Ref;
class Object {
template <class> friend class Ref;
size_t reference;
@Superstar64
Superstar64 / Unify.java
Last active June 25, 2022 20:02
Syntactic Unification in Java
/* Copyright (C) Freddy A Cubas "superstar64"
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
@Superstar64
Superstar64 / lazy.c
Last active March 12, 2022 05:34
Lazy Evaluation with Just in Time Compiled Thunks
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
typedef struct list_data (*list)();
struct list_data {
long head;
@Superstar64
Superstar64 / TypeSystem.java
Last active November 26, 2021 03:33
A Calculus of Constructions Type Checker in Java
/* Copyright (C) Freddy A Cubas "superstar64"
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
@Superstar64
Superstar64 / Freer.java
Last active November 26, 2021 04:05
Freer Monads in java
import java.util.function.Function;
// straight forward port of freer monads to java
// see http://okmij.org/ftp/Computation/free-monad.html
// lightweight higher kinded polymorphism
// see http://ocamllabs.io/higher/lightweight-higher-kinded-polymorphism.pdf
interface App<F,A> {}
@Superstar64
Superstar64 / monad.js
Last active May 12, 2021 13:20
Freer monad in javascript
/* Copyright Freddy A Cubas "superstar64"
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
@Superstar64
Superstar64 / interp.js
Last active May 5, 2021 01:10
lambda calculus interpreter in javascript
/* Copyright Freddy A Cubas "Superstar64"
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
@Superstar64
Superstar64 / parsec.cpp
Last active October 31, 2022 07:18
Proof of concept parsec style non backtracking parser combinators in C++ at compile time
/* Copyright (C) Freddy A Cubas "Superstar64"
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
@Superstar64
Superstar64 / magic.hs
Last active March 10, 2021 19:46
Bound, Enum, Show, and Eq instance for functions
import Data.List
import Data.Maybe
every :: (Bounded a, Enum a) => [a]
every = [minBound ..]
space :: (Bounded a, Enum a, Bounded b, Enum b, Eq a) => [a -> b]
space = spaceImpl every
where
spaceImpl [] = [error "lol"]