doc-src/Codegen/Thy/document/Program.tex
changeset 37432 e732b4f8fddf
parent 37428 b3d94253e7f2
child 37610 1b09880d9734
equal deleted inserted replaced
37431:e9004a3e0d94 37432:e732b4f8fddf
   340 \hspace*{0pt}structure Example :~sig\\
   340 \hspace*{0pt}structure Example :~sig\\
   341 \hspace*{0pt} ~datatype nat = Zero{\char95}nat | Suc of nat\\
   341 \hspace*{0pt} ~datatype nat = Zero{\char95}nat | Suc of nat\\
   342 \hspace*{0pt} ~type 'a semigroup\\
   342 \hspace*{0pt} ~type 'a semigroup\\
   343 \hspace*{0pt} ~val mult :~'a semigroup -> 'a -> 'a -> 'a\\
   343 \hspace*{0pt} ~val mult :~'a semigroup -> 'a -> 'a -> 'a\\
   344 \hspace*{0pt} ~type 'a monoid\\
   344 \hspace*{0pt} ~type 'a monoid\\
   345 \hspace*{0pt} ~val monoid{\char95}semigroup :~'a monoid -> 'a semigroup\\
   345 \hspace*{0pt} ~val semigroup{\char95}monoid :~'a monoid -> 'a semigroup\\
   346 \hspace*{0pt} ~val neutral :~'a monoid -> 'a\\
   346 \hspace*{0pt} ~val neutral :~'a monoid -> 'a\\
   347 \hspace*{0pt} ~val pow :~'a monoid -> nat -> 'a -> 'a\\
   347 \hspace*{0pt} ~val pow :~'a monoid -> nat -> 'a -> 'a\\
   348 \hspace*{0pt} ~val plus{\char95}nat :~nat -> nat -> nat\\
   348 \hspace*{0pt} ~val plus{\char95}nat :~nat -> nat -> nat\\
   349 \hspace*{0pt} ~val neutral{\char95}nat :~nat\\
   349 \hspace*{0pt} ~val neutral{\char95}nat :~nat\\
   350 \hspace*{0pt} ~val mult{\char95}nat :~nat -> nat -> nat\\
   350 \hspace*{0pt} ~val mult{\char95}nat :~nat -> nat -> nat\\
   356 \hspace*{0pt}datatype nat = Zero{\char95}nat | Suc of nat;\\
   356 \hspace*{0pt}datatype nat = Zero{\char95}nat | Suc of nat;\\
   357 \hspace*{0pt}\\
   357 \hspace*{0pt}\\
   358 \hspace*{0pt}type 'a semigroup = {\char123}mult :~'a -> 'a -> 'a{\char125};\\
   358 \hspace*{0pt}type 'a semigroup = {\char123}mult :~'a -> 'a -> 'a{\char125};\\
   359 \hspace*{0pt}val mult = {\char35}mult :~'a semigroup -> 'a -> 'a -> 'a;\\
   359 \hspace*{0pt}val mult = {\char35}mult :~'a semigroup -> 'a -> 'a -> 'a;\\
   360 \hspace*{0pt}\\
   360 \hspace*{0pt}\\
   361 \hspace*{0pt}type 'a monoid = {\char123}monoid{\char95}semigroup :~'a semigroup,~neutral :~'a{\char125};\\
   361 \hspace*{0pt}type 'a monoid = {\char123}semigroup{\char95}monoid :~'a semigroup,~neutral :~'a{\char125};\\
   362 \hspace*{0pt}val monoid{\char95}semigroup = {\char35}monoid{\char95}semigroup :~'a monoid -> 'a semigroup;\\
   362 \hspace*{0pt}val semigroup{\char95}monoid = {\char35}semigroup{\char95}monoid :~'a monoid -> 'a semigroup;\\
   363 \hspace*{0pt}val neutral = {\char35}neutral :~'a monoid -> 'a;\\
   363 \hspace*{0pt}val neutral = {\char35}neutral :~'a monoid -> 'a;\\
   364 \hspace*{0pt}\\
   364 \hspace*{0pt}\\
   365 \hspace*{0pt}fun pow A{\char95}~Zero{\char95}nat a = neutral A{\char95}\\
   365 \hspace*{0pt}fun pow A{\char95}~Zero{\char95}nat a = neutral A{\char95}\\
   366 \hspace*{0pt} ~| pow A{\char95}~(Suc n) a = mult (monoid{\char95}semigroup A{\char95}) a (pow A{\char95}~n a);\\
   366 \hspace*{0pt} ~| pow A{\char95}~(Suc n) a = mult (semigroup{\char95}monoid A{\char95}) a (pow A{\char95}~n a);\\
   367 \hspace*{0pt}\\
   367 \hspace*{0pt}\\
   368 \hspace*{0pt}fun plus{\char95}nat (Suc m) n = plus{\char95}nat m (Suc n)\\
   368 \hspace*{0pt}fun plus{\char95}nat (Suc m) n = plus{\char95}nat m (Suc n)\\
   369 \hspace*{0pt} ~| plus{\char95}nat Zero{\char95}nat n = n;\\
   369 \hspace*{0pt} ~| plus{\char95}nat Zero{\char95}nat n = n;\\
   370 \hspace*{0pt}\\
   370 \hspace*{0pt}\\
   371 \hspace*{0pt}val neutral{\char95}nat :~nat = Suc Zero{\char95}nat;\\
   371 \hspace*{0pt}val neutral{\char95}nat :~nat = Suc Zero{\char95}nat;\\
   373 \hspace*{0pt}fun mult{\char95}nat Zero{\char95}nat n = Zero{\char95}nat\\
   373 \hspace*{0pt}fun mult{\char95}nat Zero{\char95}nat n = Zero{\char95}nat\\
   374 \hspace*{0pt} ~| mult{\char95}nat (Suc m) n = plus{\char95}nat n (mult{\char95}nat m n);\\
   374 \hspace*{0pt} ~| mult{\char95}nat (Suc m) n = plus{\char95}nat n (mult{\char95}nat m n);\\
   375 \hspace*{0pt}\\
   375 \hspace*{0pt}\\
   376 \hspace*{0pt}val semigroup{\char95}nat = {\char123}mult = mult{\char95}nat{\char125}~:~nat semigroup;\\
   376 \hspace*{0pt}val semigroup{\char95}nat = {\char123}mult = mult{\char95}nat{\char125}~:~nat semigroup;\\
   377 \hspace*{0pt}\\
   377 \hspace*{0pt}\\
   378 \hspace*{0pt}val monoid{\char95}nat = {\char123}monoid{\char95}semigroup = semigroup{\char95}nat,~neutral = neutral{\char95}nat{\char125}\\
   378 \hspace*{0pt}val monoid{\char95}nat = {\char123}semigroup{\char95}monoid = semigroup{\char95}nat,~neutral = neutral{\char95}nat{\char125}\\
   379 \hspace*{0pt} ~:~nat monoid;\\
   379 \hspace*{0pt} ~:~nat monoid;\\
   380 \hspace*{0pt}\\
   380 \hspace*{0pt}\\
   381 \hspace*{0pt}fun bexp n = pow monoid{\char95}nat n (Suc (Suc Zero{\char95}nat));\\
   381 \hspace*{0pt}fun bexp n = pow monoid{\char95}nat n (Suc (Suc Zero{\char95}nat));\\
   382 \hspace*{0pt}\\
   382 \hspace*{0pt}\\
   383 \hspace*{0pt}end;~(*struct Example*)%
   383 \hspace*{0pt}end;~(*struct Example*)%