Polymorphism and Higher Order Functions

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/12

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 4:57 PM on 4/3/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

13 Terms

1
New cards

Polymorphic List Definition

  • Inductive list (A : Type) : Type

  • nil : list A

  • cons : A -> list A -> list A

  • Parameterized by element type A

  • Allows reuse for any type.

2
New cards

map Function Type

  • map : forall (A B : Type), (A -> B) -> list A -> list B
  • Takes a function from A to B
  • Operates on a list of A
  • Returns a list of B
  • Higher-order and polymorphic.
3
New cards

Haskell Type Variables

  • Type variables a, b in signatures like map :: (a -> b) -> [a] -> [b]
  • Prenex universally quantified
  • Expressed as map : forall a b. (a -> b) -> [a] -> [b].
4
New cards

Haskell Type Constructor

  • [\_] : Type -> Type (list type constructor)
  • (->) : Type -> Type -> Type (function type constructor)
  • Types are first-class in type system.
5
New cards

Limitation of Haskell Types

  • Cannot directly type strange g = [g True, g 0]
  • g would need both Bool → ? and nat → ?
  • Requires impredicative polymorphism (g : forall A, A → B).
6
New cards

Rocq Strange Function Type

  • strange : forall (B : Type), (forall (A : Type), A -> B) -> list B
  • g must work for all argument types A
  • Returns same result type B.
7
New cards

Dependent Types

  • vec\_app : forall (n m : nat) (A : Type)
  • Vec n A -> Vec m A -> Vec (n + m) A
  • Type depends on value (length n)
  • Enables precise length specifications.
8
New cards

Rocq Type Hierarchy

  • 0 : nat
  • nat : Set
  • Set : Type
  • Prop : Type
  • Type : Type (with universes to avoid paradoxes)
  • Types themselves have types (sorts).
9
New cards

Rocq vs Haskell Types

  • Rocq types are terms with t : τ relation
  • Supports arbitrary quantification, dependent types
  • Haskell types are prenex polymorphic only.
10
New cards

Termination in Rocq

  • Rocq's λ-calculus (Calculus of Inductive Constructions) is terminating
  • Ensures all functions are total
  • Guarantees proofs are consistent.
11
New cards

Polymorphic Map Implementation

  • Fixpoint map (A B : Type) (f : A -> B) (l : list A) : list B
  • match l with
  • nil \_ => nil B
  • cons \_ x xs => cons B (f x) (map A B f xs) end
  • Explicit type arguments.
12
New cards

System F

  • Haskell's core type system (System F)
  • Supports parametric polymorphism with prenex universal quantification
  • Basis for polymorphic programming.
13
New cards

λ-cube (Barendregt)

  • Framework classifying type systems by three axes
  • Polymorphism (types depending on types)
  • Dependent types (types depending on terms)
  • Operators (terms depending on types)
  • Rocq near the top.