linear-type-implementer
Skill17 starsChanged 9 months agoApache-2.0View on GitHub
Implements linear lambda calculus with linear types. Use when: (1) Building
In this repository98 other files it gives its agents.
- abstract-interpretation-engineSkill
- abstract-machineSkill
- acsl-annotation-assistantSkill
- actor-model-implementerSkill
- algebraic-effectsSkill
- alias-and-points-to-analysisSkill
- axiomatic-semanticsSkill
- bidirectional-type-checkingSkill
- bisimulation-checkerSkill
- capability-systemSkill
- closure-converterSkill
- common-subexpression-eliminatorSkill
- concurrency-verifierSkill
- constant-propagation-passSkill
- contextual-equivalenceSkill
- control-flow-analysisSkill
- coq-proof-assistantSkill
- cps-transformerSkill
- dafny-verifierSkill
- dataflow-analysis-frameworkSkill
- dead-code-eliminatorSkill
- defunctionalizationSkill
- denotational-semantics-builderSkill
- dependent-type-implementerSkill
- dsl-embeddingSkill
- effect-handlers-implementerSkill
- effect-systemSkill
- effect-type-systemSkill
- escape-analysisSkill
- existential-typesSkill
- ffi-designerSkill
- fuzzer-generatorSkill
- gadt-implementerSkill
- garbage-collector-implementerSkill
- graalvm-truffle-implementerSkill
- gradual-typing-implementerSkill
- higher-order-abstract-syntaxSkill
- hoare-logic-verifierSkill
- incremental-computationSkill
- information-flow-analyzerSkill
- inline-expanderSkill
- interprocedural-analysisSkill
- invariant-generatorSkill
- jit-compiler-builderSkill
- lambda-calculus-interpreterSkill
- language-server-protocolSkill
- lean-proverSkill
- lexer-generatorSkill
- liveness-analysisSkill
- llvm-backend-generatorSkill
- lock-free-data-structureSkill
- loop-optimizerSkill
- loop-termination-proverSkill
- macro-expanderSkill
- memory-allocatorSkill
- message-passing-systemSkill
- mlir-dialect-designerSkill
- model-checkerSkill
- module-systemSkill
- monad-transformerSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 34
Implements linear functions: - Use exactly once
- Distinctive: line 35
Handles affine types: - Use at most once
- Distinctive: line 37
Enforces linearity: - Every variable used exactly once
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Linear Type Implementer
Implements linear logic and linear lambda calculus.
When to Use
- Resource-aware programming
- Quantum computing (Quipper)
- Verified memory management
- Session types
- Database connections
What This Skill Does
- Implements linear functions - Use exactly once
- Handles affine types - Use at most once
- Provides modalities - ! (of course), ? (why not)
- Enforces linearity - Every variable used exactly once
Core Theory
Linear Logic:
- A ⊗ B : Times (pair)
- A & B : With (product)
- A ⊕ B : Plus (sum)
- A ⅋ B : Par (implication dual)
- !A : Of course (persistent)
- ?A : Why not (consumable)
- A → B : Linear implication (!A ⊢ B)
Linear Lambda Calculus:
λx. e : Linear abstraction
x • y : Multiplicative applicationImplementation
(* Linear type system *)
type linear_term =
| LVar of string
| LAbs of string * linear_term
| LApp of linear_term * linear_term
| LPair of linear_term * linear_term
| LFst of linear_term
| LSnd of linear_term
| LInl of linear_term
| LInr of linear_term
| LCase of linear_term * linear_term * linear_term
| LLet of string * linear_term * linear_term
| LNil
type linear_type =
| LBase
| LFun of linear_type * linear_type (* A → B (linear) *)
| LWith of linear_type * linear_type (* A & B *)
| LTimes of linear_type * linear_type (* A ⊗ B *)
| LPlus of linear_type * linear_type (* A ⊕ B *)
| LOne (* Unit *)
| LModal of linear_type (* !A *)
(* Context: linear (used once) or affine (used 0 or 1) *)
type linear_context = (string * linear_type * usage) list
and usage = Linear | Affine
(* Type checking with substructural logic *)
let rec check_linear (ctx : linear_context) (t : linear_term) (ty : linear_type) : bool =
match t, ty with
| LAbs (x, body), LFun (a, b) ->
let ctx' = add_binding ctx x a Linear in
check_linear ctx' body b
| LPair (m, n), LTimes (a, b) ->
check_linear ctx m a && check_linear ctx n b
| LFst p, LWith (a, _) ->
check_linear ctx p (LWith (a, LBase))
| LSnd p, LWith (_, b) ->
check_linear ctx p (LWith (LBase, b))
| LLet (x, m, n), b ->
(* Linear let: consume m exactly once *)
check_linear ctx m (infer_linear ctx m) &&
let ctx' = remove_binding ctx x in
check_linear ctx' n b
| _ -> false
(* Every variable must be used exactly once *)
let check_usage (ctx : linear_context) (t : linear_term) : bool =
let uses = count_uses t in
List.for_all (fun (x, _, usage) ->
match usage with
| Linear -> uses x = 1 (* Exactly once *)
| Affine -> uses x <= 1 (* At most once *)
) ctxLinear Logic connectives
(* Linear logic operations *)
(* Tensor (⊗) - independent resources *)
let tensor (a : linear_type) (b : linear_type) : linear_type =
LTimes (a, b)
(* With (&) - can choose either *)
let with_type (a : linear_type) (b : linear_type) : linear_type =
LWith (a, b)
(* Plus (⊕) - tagged union *)
let plus (a : linear_type) (b : linear_type) : linear_type =
LPlus (a, b)
(* Of course (!) - reusable *)
let of_course (a : linear_type) : linear_type =
LModal a
(* Linear implication: A ⊸ B = !A → B *)
let linear_imply (a : linear_type) (b : linear_type) : linear_type =
LFun (of_course a, b)Evaluation
(* Linear evaluator *)
type linear_value =
| VLam of (linear_value -> linear_value)
| VPair of linear_value * linear_value
| VInl of linear_value
| VInr of linear_value
| VUnit
| VRef of int (* Reference cell *)
let rec eval (t : linear_term) (ρ : linear_value list) : linear_value =
match t with
| LVar i -> List.nth ρ i
| LAbs (x, body) ->
VLam (fun v -> eval body (v :: ρ))
| LApp (m, n) ->
(match eval m ρ with
| VLam f -> f (eval n ρ)
| _ -> failwith "linear apply")
| LPair (m, n) ->
VPair (eval m ρ, eval n ρ)
| LLet (x, m, n) ->
let v = eval m ρ in
(* Important: consume the value! *)
consume v;
eval n (v :: ρ)
| LNil -> VUnit
(* Consumption - linear values cannot be duplicated *)
and consume (v : linear_value) : unit =
match v with
| VRef r ->
(* Mark reference as used *)
ref_used r := true
| VPair (a, b) ->
consume a; consume b
| _ -> ()Linear Resources
(* Resource management example *)
(* File handle linear type *)
type file_handle = { fd : int }
(* Linear file operations *)
let open_file (path : string) : file_handle =
{ fd = Unix.openfile path [Unix.O_RDONLY] 0 }
let close_file (h : file_handle) : unit =
Unix.close h.fd
(* Linear read - consumes handle *)
let read_file (h : file_handle) : string * file_handle =
let buf = Bytes.create 100 in
let n = Unix.read h.fd buf 0 100 in
(Bytes.sub_string buf 0 n, h)
(* Usage: must use exactly once *)
let process_file (path : string) =
let h = open_file path in
let content, h' = read_file h in
close_file h'; (* Must close exactly once *)
contentQuantum Computing Application
(* Linear types for quantum computing (Quipper) *)
(* Qubit: linear (cannot duplicate) *)
type qubit = Q of int
(* Quantum gate: linear function *)
let hadamard (q : qubit) : qubit =
(* Creates superposition - still linear! *)
apply_gate H q
(* Linear map *)
let quantum_not (q : qubit) : qubit =
apply_gate X q
(* Measurement - consumes qubit, returns classical bit *)
let measure (q : qubit) : bool =
(* Collapse superposition - qubit is consumed *)
Random.bool () (* Simplified *)Key Concepts
| Concept | Description |
| Linear | Use exactly once |
| Affine | Use 0 or 1 times |
| ⊗ (tensor) | Independent resources |
| & (with) | Can select |
| ⊕ (plus) | Tagged choice |
| ! (of course) | Unlimited use |
Duplication Handling
| Strategy | Description |
| Linear | No duplication |
| Affine | Copy at most once |
| Relevant | Must use |
| Ordered | Sequential use |
Tips
- Track variable usage carefully
- Handle modality (!) for sharing
- Consider copyable types
- Implement borrowing (like Rust)
Canonical References
| Reference | Why It Matters |
| Girard, "Linear Logic" (Theoretical Computer Science, 1987) | Original linear logic foundation |
| Abramsky, "Computational Interpretations of Linear Logic" (1993) | Semantic foundations for programming |
| Wadler, "Linear Types Can Change the World!" (2000) | Linear types in programming |
| Baker, "Use-Once Variables and Linear Objects" (1994) | Linear objects and resources |
Related Skills
session-type-checker- Session typesownership-type-system- Rust-style ownershipeffect-type-system- Effect tracking
Research Tools & Artifacts
Linear type implementations:
| System | Language | What to Learn |
| Linear Haskell | Haskell | Quotation |
| Idris 2 | Idris | Linear types |
| Quipper | Haskell | Quantum computing |
| Rust | Rust | Ownership/borr |
Key Papers
- Girard - Linear logic
- Wadler - Linear types in programming
Research Frontiers
1. Linear Type Systems
- Goal: Resource safety
- Approach: Modal types
Implementation Pitfalls
| Pitfall | Real Consequence | Solution |
| Wrong linearity | Resource leaks | Check usage |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

