doc-src/IsarAdvanced/Codegen/Thy/examples/monotype.ML
author haftmann
Wed, 30 May 2007 21:09:13 +0200
changeset 23132 ae52b82dc5d8
parent 23107 0c3c55b7c98f
child 23850 f1434532a562
permissions -rw-r--r--
updated
     1 structure ROOT = 
     2 struct
     3 
     4 structure Nat = 
     5 struct
     6 
     7 datatype nat = Zero_nat | Suc of nat;
     8 
     9 fun eq_nat Zero_nat (Suc m) = false
    10   | eq_nat (Suc n) Zero_nat = false
    11   | eq_nat (Suc n) (Suc m) = eq_nat n m
    12   | eq_nat Zero_nat Zero_nat = true;
    13 
    14 fun plus_nat (Suc m) n = plus_nat m (Suc n)
    15   | plus_nat Zero_nat n = n;
    16 
    17 end; (*struct Nat*)
    18 
    19 structure List = 
    20 struct
    21 
    22 fun zip xs (y :: ys) =
    23   (case xs of [] => [] | z :: zs => (z, y) :: zip zs ys)
    24   | zip xs [] = [];
    25 
    26 fun null (x :: xs) = false
    27   | null [] = true;
    28 
    29 fun list_all p (x :: xs) = p x andalso list_all p xs
    30   | list_all p [] = true;
    31 
    32 fun size_list (a :: lista) =
    33   Nat.plus_nat (size_list lista) (Nat.Suc Nat.Zero_nat)
    34   | size_list [] = Nat.Zero_nat;
    35 
    36 fun list_all2 p (x :: xs) (y :: ys) = p x y andalso list_all2 p xs ys
    37   | list_all2 p xs [] = null xs
    38   | list_all2 p [] ys = null ys
    39   | list_all2 p xs ys =
    40     Nat.eq_nat (size_list xs) (size_list ys) andalso
    41       list_all (fn a as (aa, b) => p aa b) (zip xs ys);
    42 
    43 end; (*struct List*)
    44 
    45 structure Codegen = 
    46 struct
    47 
    48 datatype monotype = Mono of Nat.nat * monotype list;
    49 
    50 fun eq_monotype (Mono (tyco1, typargs1)) (Mono (tyco2, typargs2)) =
    51   Nat.eq_nat tyco1 tyco2 andalso
    52     List.list_all2 eq_monotype typargs1 typargs2;
    53 
    54 end; (*struct Codegen*)
    55 
    56 end; (*struct ROOT*)