Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE
PolyKinds,
InstanceSigs,
DataKinds,
GADTs #-}
module Cat where
import Control.Category
import Prelude hiding ((.))
efactor' :: Integer -> Float -> Float
efactor' x y
| ef < 1.3 = 1.3
| ef > 2.5 = 2.5
| otherwise = ef
where ef = y - 0.8 + 0.28 * q - 0.02 * q * q
q = fromIntegral x :: Float
Class Container : Type :=
{ Shape : Type;
Pos : Shape -> Type;
}.
Inductive Ext (C : Container) (A : Type) :=
| ext : forall s, (forall p : Pos s, A) -> Ext C A.
Class HContainer : Type :=
{ C0 :> Container;
@Lysxia
Lysxia / LC.v
Created March 9, 2019 21:45
Lambda-calculus in 50 lines of Coq (call-by-name).
(* Untyped lambda calculus *)
(* Terms with free variables in [V]. *)
Inductive term {V : Type} : Type :=
| Var : V -> term
| App : term -> term -> term
| Lam : @term (unit + V) -> term
.
Arguments term : clear implicits.
@Lysxia
Lysxia / turing.v
Created March 10, 2019 20:31
Turing machines in 50 Lines Of Coq
Require Import List.
Import ListNotations.
Notation "0" := false : bool_scope.
Notation "1" := true : bool_scope.
Local Open Scope bool_scope.
Inductive tape :=
| Tape (l : list bool) (b : bool) (r : list bool)
.
withFunction :: (Int -> IO b) -> IO b
withFunction fun = do
let val = 3
fun val
class WithFunction proxy where
withFunction_ :: proxy -> (Int -> IO b) -> IO b
data Number1 = Number1
Set Primitive Projections.
Record pr : Type := { fst : nat ; snd : nat }.
Goal forall x : pr, x = let (u, v) := x in {| fst := u ; snd := v |}.
Proof.
intros. cbn.
reflexivity.
Qed.
@Lysxia
Lysxia / coinduction.v
Created March 29, 2019 18:12
A presentation about coinductive types (given at UPenn's PLClub)
Require Arith.
Require Import List.
Import ListNotations.
(** * Coinductive types and coinduction *)
Inductive bitarray : nat -> Type :=
| empty : bitarray O
| cons : forall (sz : nat), bool -> bitarray sz -> bitarray (S sz)
.
Notation "{| |}" := empty.
Notation "{| x |}" := (cons _ x empty).
Notation "{| x ; y ; .. ; z |}" := (cons _ x (cons _ y .. (cons _ z empty) .. )).
Check {| true; true; false |}.
Require Import List.
Import ListNotations.
Fixpoint tuple (ts : list Type) : Type :=
match ts with
| [] => unit
| t :: ts' => (t * tuple ts')%type
end.