Skip to content

Instantly share code, notes, and snippets.

View dhil's full-sized avatar

Daniel Hillerström dhil

View GitHub Profile
@dhil
dhil / Y.scala
Created September 12, 2019 04:17
Typing the Y combinator in Scala.
// Typing the Y combinator in Scala 2.
// $ scalac Y.scala
// $ scala Y
// 720
// Succ(Succ(Succ(Succ(Succ(Succ(Zero))))))
object Y {
case class Fix[A,B](f : Fix[A,B] => A => B) {
def apply(x : Fix[A,B]) = f(x)
@dhil
dhil / y.sml
Last active September 11, 2019 22:19
Typing the Y combinator in SML/NJ.
(* Typing the Y combinator in SML/NJ.
* $ sml y.sml
720
Succ(Succ(Succ(Succ(Succ(Succ(Zero))))))
*)
datatype 'a fix = Fix of ('a fix -> 'a)
fun fix f = Fix f
fun unfix (Fix f) = f
@dhil
dhil / Y.hs
Created August 23, 2019 07:18
Typing the Y combinator in Haskell.
{- Typing the Y combinator in Haskell.
- $ runghc Y.hs
720
Succ (Succ (Succ (Succ (Succ (Succ Zero)))))
-}
newtype Fix a = Fix { unfix :: Fix a -> a }
fix :: (Fix a -> a) -> Fix a
fix x = Fix x
@dhil
dhil / y.ml
Last active January 28, 2023 03:44
Typing the Y combinator in OCaml.
(* Typing the Y combinator in OCaml.
* $ ocaml y.ml
720
Succ(Succ(Succ(Succ(Succ(Succ(Zero))))))
*)
type 'a fix = Fix of ('a fix -> 'a)
let fix x = Fix x
let unfix (Fix x) = x
@dhil
dhil / y.links
Created August 20, 2019 03:52
Typing the Y combinator in Links.
@dhil
dhil / Y.java
Created August 16, 2019 21:36
Typing the Y combinator in Java.
// Typing the Y combinator in Java (tested with OpenJDK 11.0.4).
// $ javac Y.java
// $ java Y
// 720
// Succ(Succ(Succ(Succ(Succ(Succ(Zero))))))
import java.util.function.Function;
// A typed implementation of the Y-combinator.
public class Y {
@dhil
dhil / open-wsl.sh
Created August 16, 2019 19:28
Open files in Windows from within the Windows Subsystem for Linux (WSL)
# Open files in Windows from within WSL.
function _windows_open()
{
# Absolute, inside WSL, path to the file.
local file=$(readlink -e "$1")
if [[ ! (-f "$file" || -d "$file") ]]; then
echo "error: no such file '$1'"
return 1
else
# Convert slashes into backslashes.
@dhil
dhil / y.dart
Created January 4, 2019 09:19
Typing the Y combinator in Dart
// Typing the Y combinator in Dart.
class Fix<A> {
A Function(Fix<A>) f;
Fix.inject(this.f);
A Function(Fix<A>) get project => f;
}
// fix : (Fix<A> -> a) -> Fix<A>.
Fix<A> fix<A>(A Function(Fix<A>) f) => Fix.inject(f);
@dhil
dhil / handlers.config
Last active July 14, 2017 23:19
Links Systemd service unit
make_cache=false
use_cache=false
cache_directory=$LINKSHOME/cache
prelude=$LINKSHOME/prelude.links
jslibdir=$LINKSHOME/lib/js
jsliburl=/lib/
database_args=:links:
database_driver=postgresql
port=10088
js_pretty_print=true
@dhil
dhil / ocaml_of_links-polymorphic-effects-signature
Created April 19, 2016 14:44
Encoding effects á la Links in OCaml