Skip to content

Instantly share code, notes, and snippets.

@pbl64k
pbl64k / runme.hh
Last active August 20, 2018 10:36
Type system unsoundness in HHVM 3.27.1: inout parameters, shape subtyping, bounded quantification
<?hh
require_once(__DIR__ . '/soundness.hh');
breakage();
@pbl64k
pbl64k / encodings.md
Created June 8, 2018 09:08 — forked from zmactep/encodings.md
Number encodings

Alternative to the Church, Scott and Parigot encodings of data on the Lambda Calculus.

When it comes to encoding data on the pure λ-calculus (without complex extensions such as ADTs), there are 3 widely used approaches.

Church Encoding

The Church Encoding, which represents data structures as their folds. Using Caramel’s syntax, the natural number 3 is, for example. represented as:

0 c0 = (f x -> x)
1 c1 = (f x -> (f x))
2 c2 = (f x -&gt; (f (f x)))
@pbl64k
pbl64k / Para2.idr
Last active March 14, 2016 19:05
Parigot/Church-Scott encoding of naturals in CoC (by way of Idris)
Fix : (Type -> Type) -> Type
Fix f = {x : Type} -> (f x -> x) -> x
fold : Functor f => {x : Type} -> (f x -> x) -> Fix f -> x
fold k t = t k
embed : Functor f => f (Fix f) -> Fix f
embed s k = k (map (fold k) s)
project : Functor f => Fix f -> f (Fix f)
%default total
data Mu : (Type -> Type) -> Type where
In : f (Mu f) -> Mu f
out : Mu f -> f (Mu f)
out (In x) = x
data LstF : Type -> Type -> Type where
LF : ({c : Type} -> (Maybe (a, Unit -> c, b) -> c) -> c) -> LstF a b
@pbl64k
pbl64k / para.hs
Last active March 4, 2016 09:34
Possibly pointless? encoding of lists as their own paramorphisms.
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE Rank2Types #-}
import Data.Maybe
data Fix f = Fix { unFix :: f (Fix f) }
data ListF a b = LF { unLF :: forall c. (Maybe (a, (c, b)) -> c) -> c }
type List a = Fix (ListF a)
@pbl64k
pbl64k / Dummy.hh
Created January 15, 2016 15:41
Hack typechecker disagrees with run-time re at() signature in ConstIndexAccess
<?hh // strict
final class Dummy<Tx> implements ConstIndexAccess<int, Tx>
{
final public function __construct(private Tx $x) { }
final public function at(int $ix): Tx
{
return $this->x;
}
@pbl64k
pbl64k / tc-bug2-minimal-runme.hh
Created October 26, 2015 12:19
Improved sample case for Hack's type checker failure -- this actually fails at runtime
<?hh
require_once(__DIR__.'/tc-bug2-minimal.hh');
test();
@pbl64k
pbl64k / tc-bug2-minimal-runme.hh
Created October 26, 2015 10:54
Hack's type checker fails to report type mismatch in strict mode
<?hh
require_once(__DIR__.'/tc-bug2-minimal.hh');
test();
@pbl64k
pbl64k / minimum-test-runme.hh
Created October 23, 2015 11:18
Type erasure allows unsafe coercions using generics even in Hack's strict mode.
<?hh
require_once(__DIR__.'/minimum-test.hh');
Unsafe::test();
@pbl64k
pbl64k / adt.idr
Created August 18, 2015 09:54
...need indexed functors...
%default total
data Id : Type -> Type where
I : a -> Id a
data Const : (a : Type) -> (b : Type) -> Type where
K : a -> Const a b
data Sum : (a : Type -> Type) -> (b : Type -> Type) -> (c : Type) -> Type where
SumL : a c -> Sum a b c