Skip to content

Instantly share code, notes, and snippets.

@Superstar64
Superstar64 / MergeInsert.hs
Last active May 29, 2020 18:50
Merge Insertion(Ford-Johnson) Sort in Haskell
{-
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
@Superstar64
Superstar64 / erasure.d
Last active January 27, 2021 18:14
Type Erasure In D
/*
Copyright (C) Freddy A Cubas "Superstar64" 2020
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
@Superstar64
Superstar64 / Lazy_List.java
Last active November 26, 2021 03:54
Lazy Lists in Java and some basic functions on them
/*
Copyright (C) Freddy A Cubas "Superstar64" 2020
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
@Superstar64
Superstar64 / Logic.hs
Created June 25, 2020 05:16
Embedding Logic in Haskell
{-# Language DataKinds, TypeOperators, TypeFamilies, GADTs #-}
import Prelude hiding (Left,Right)
-- based of figure 1 of https://homepages.inf.ed.ac.uk/wadler/papers/lineartaste/lineartaste-revised.pdf
data a :* b = Product a b
data a :+ b = Left a | Right b
type family a :++ b where
@Superstar64
Superstar64 / Match.java
Last active December 10, 2021 04:55
Typesafe Tagged Union in Java using Scott Encoding
// public domain
import java.util.function.Function;
interface Either<A, B> {
<C> C match(Function<A, C> left, Function<B, C> right);
}
class Left<A, B> implements Either<A, B> {
final A get;
Left(A get) {
this.get = get;
@Superstar64
Superstar64 / lambda.sh
Last active July 20, 2020 19:51
A Lambda Calculus Model in POSIX sh
# run with bash -x for a wild ride
# escaping with '\s' messes up dash, use '-s' instead
escape(){
if test -n "$1"; then
if test "${1%"${1#?}"}" = ' '; then
echo '-s'"$(escape "${1#?}")"
elif test "${1%"${1#?}"}" = '-'; then
echo '--'"$(escape "${1#?}")"
else
@Superstar64
Superstar64 / Lambda.hs
Last active November 24, 2020 22:32
Extendable Lambda Calculus Interpreter
{- Copyright (C) Freddy Angel 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 / semantic_editor.js
Last active April 30, 2022 19:14
Semantic Editor Combinators in javascript
// see http://conal.net/blog/posts/semantic-editor-combinators
const o = (...f) => {
if(f.length === 0) {
return x => x;
} else {
return x => f[0](o(...f.slice(1))(x));
}
};
@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"]
@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: