Functional Programming & Proofs


Trees and languages

  1. (t lists)
    How to model streams that can be either empty or composed with a value and another stream ?
type 't Str = End | Add of 't*('t Str);;

let s = Add (14,Add(7,Add(16,End)));;

let (<>) v s = Add (v,s);;
let s = 14 <> (7 <> (16 <> End));;
  1. How to define a catenation operator on streams ?
let rec cat s1 s2 = 
  match s1 with 
  | End       -> s2
  | Add(v,s3) -> Add(v,cat s3 s2);;

cat s s;;

6 - 10