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