Require Import Arith. Require Import List. Open Scope list_scope. Compute 1 :: 2 :: 3 :: 4 :: nil. Compute cons 1 (cons 2 (cons 3 (cons 4 nil))). (* Compute 1::true::nil. <-- ERROR *) Inductive nat_or_bool : Type := | Nat (n:nat): nat_or_bool | Bool (b:bool): nat_or_bool. Compute (Nat 1)::(Bool true)::nil. Fixpoint length1 (s:list nat) : nat := match s with | nil => 0 | _ :: t => S (length1 t) end. Compute length1 (5::4::3::nil). Fixpoint length2 (A:Type) (s:list A) : nat := match s with | nil => 0 | _ :: t => S (length2 A t) end. Compute length2 nat (5::4::3::nil). Compute length2 nat_or_bool ((Nat 1)::(Bool true)::nil). Fixpoint length3 {A:Type} (s:list A) : nat := match s with | nil => 0 | _ :: t => S (length3 t) end. Compute length3 (5::4::3::nil). Compute length3 ((Nat 1)::(Bool true)::nil). Print list. Definition ident {A:Type} (x:A) := x. Compute ident 3. Compute ident true. Check ident. Compute @ident nat 3. Check @ident. Definition apply {A:Type} {B:Type} (f: A -> B) (x:A) := f x. Compute apply length3 (5::4::3::nil). Compute apply length3 ((Nat 1)::(Bool true)::nil). Check @apply. Definition addone (n:nat) := n+1. Compute apply addone 3. Compute apply (fun n => n+1) 3. Fixpoint map {A:Type} {B:Type} (f: A -> B) (s: list A) : list B := match s with | nil => nil | h :: t => (f h) :: (map f t) end. Compute map addone (1::2::3::nil). Compute map negb (true::false::false::nil). Check @map. Compute (fun (n:nat) => n+10) 3. Definition addx (x:nat) : nat -> nat := (fun (y:nat) => x+y). Compute (addx 10) 3. Compute addx 10 3. Check addx. Definition addx2 (x:nat) (y:nat) := x+y. Compute (addx2 10) 3. Compute (Nat.add 10) 3. Compute Nat.add 10 3. Check 3. Check nat. Check bool. Check Set. Check Type.