Skip to content

Instantly share code, notes, and snippets.

View biboudis's full-sized avatar

Aggelos Biboudis biboudis

View GitHub Profile
@biboudis
biboudis / power.ml
Last active October 8, 2018 18:09
Staged power, with fixed, with staged fix.
(* http://fssnip.net/sE in BER MetaOCaml *)
open Runcode;;
let rec fix : (('a -> 'b) -> ('a -> 'b)) -> 'a -> 'b = fun f x ->
f (fix f) x;;
let fix' : (('a -> 'b) code -> ('a -> 'b) code) -> ('a -> 'b) code = fun f ->
.< fun x -> let rec loop x = (fun f' -> .~(f .<f'>.) ) loop x in
loop x >.;;
@biboudis
biboudis / gist:52fa07ba3ea1abc7ce20
Last active November 30, 2018 11:52
Shift/Reset Java
package builders;
import java.util.function.Function;
public class Cont {
interface K<A, B, C> extends Function<Function<A, B>, C>{ }
/*
* Step 1: https://en.wikibooks.org/wiki/Haskell/Continuation_passing_style
* ---> just transforming continuations of type (a->r)->r to polymorphic (a->b)->c
@biboudis
biboudis / Virtualized.scala
Last active December 2, 2020 12:39
Virtualization in Scala 3 with givens
import scala.quoted._
import scala.quoted.util._
import scala.language.implicitConversions
trait Virtualized {
type Cde[A]
given IntPrimitiveMethods as PrimitiveMethods[Int] = IntPrimitiveMethodsImpl
protected val IntPrimitiveMethodsImpl: PrimitiveMethods[Int] = new PrimitiveMethods[Int]{ }
@biboudis
biboudis / BFN.scala
Last active December 8, 2020 00:02
Breadth-first labeling via queue/zipper in Scala
import org.junit.Test
import org.junit.Assert._
import scala.util.chaining._
import scala.collection.mutable.ListBuffer
import scala.language.implicitConversions
// Breadth-first labeling -- http://okmij.org/ftp/Algorithms/BFN.html
// Breadth-First Numbering: An Algorithm in Pictures -- https://okasaki.blogspot.com/2008/07/breadth-first-numbering-algorithm-in.html
// The Under-Appreciated Unfold -- https://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/unfold.ps.gz
class BFNTest {
@biboudis
biboudis / Matrix.scala
Last active January 11, 2024 14:50
Type your matrices for great good
import scala.compiletime.ops._
import scala.compiletime.ops.int._
import scala.compiletime.ops.any._
/**
* Type your matrices for great good: a Haskell library of typed matrices and applications (functional pearl)
* https://dl.acm.org/doi/10.1145/3406088.3409019
*/
object Test {