This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Operations are structural typed in Links, therefore operation names are not declared before use. | |
In OCaml operations are nomial. This difference is not really an issue as we can simply collect all operations from the Links IR and declare them globally in OCaml. | |
However, Links' presence polymorphism introduces a small problem as operation signatures can change throughout a computation! | |
As an example of this consider the following: | |
sig fooInt : (() {Foo:(Int) {}-> Int|e}~> Int) -> | |
() {Foo{_} |e}~> Int | |
fun fooInt(m)() { | |
open handle(m) { | |
case Foo(42,k) -> k(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Typing the Y combinator in Links. | |
# links> examples(); | |
# 720 | |
# Succ(Succ(Succ(Succ(Succ(Succ(Zero)))))) | |
# () : () | |
sig y : (((a) ~e~> b) ~e~> (a) ~e~> b) -> (a) ~e~> b | |
fun y(f) { | |
fun g(x : (mu f . (((f) ~e~> (a) ~e~> b))))(a) { | |
f(x(x))(a) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
OlderNewer