Ремонт принтеров, сканнеров, факсов и остальной офисной техники


назад Оглавление вперед




[31]

structure Stack : STACK = struct

datatype a stack = nilstack I push of a * a stack

exception pop and top

fun empty(nilstack) = true

I empty = false fun pop(push( ,s)) = s

I pop = raise pop fun top(push(x, )) = x

I top = raise top

Ответ 3.2.6:

structure Exp : EXP = struct

datatype id = Id of string datatype exp = Var of id

I App of id * (exp list)

signature SUBST = sig

structure E : EXP type subst

val subst: (E.id * E.exp) list -> subst val lookup : E.id * subst -> E.exp val substitute : subst -> E.exp -> E.exp end

structure Subst: SUBST = struct

structure E = Exp type subst = (E.id * E.exp) list fun subst(x) = x fun lookup(id, Q) = E.Var id I lookup (id, (id,e)::1) =

if id=id then e else lookup(id,1) fun substitute s (E.Var id) = lookup(id.s) I substitute s (E.App(id.args)) =

E.App(id, map(substitute s) args)

end Ответ 3.3.1:

abstraction Rect: COMPLEX =


datatype complex = rect of real*real

exception divide

fun rectangular{real.imag} =

rect(real,imag) fun plus(rect(a,b), rect(c.d)) = rect(a+c, b+d) fun minus(rect(a,b), rect(c.d)) = rect(a-c, b-d) fun times(rect(a,b), rect(c.d)) =

rect(a*c-b*d, a*d+b*c) fun divide(rect(a,b), rect(c.d)) = let val cd2 = c*c+d*d in

if cd2=0.0 then raise divide else rect ((a*c+b*d)/cd2, (b*c-a*d)/cd2 ) end

fun eq(rect(a,b), rect(c.d)) = (a=c) andalso (b=d) fun real part(rect(a, )) = a fun imag part(rect( ,b)) = b end

Ответ 3.4.1:

signature ORD = sig

type elem

val eq : elem*elem -> bool val le : elem*elem -> bool end

signature SET = sig

type set

structure 0 : ORD val emptyset: set val singleton : O.elem -> set val member: O.elem * set -> bool val union : set * set -> set val intersect: set * set -> set end

functor Set(0 : ORD) : SET = struct

datatype set = set of O.elem list

structure 0=0

val emptyset = set []

fun singleton e = set [e]


fun member(е, set 1) = let fun find [] = false

I find (h::t) = if O.eq(e.h) then true

else if 0.1t(e,h) then false else find(t)

in find 1 end fun union(set 1, set 1) = let fun merge([],1) = 1 I merged, []) = 1

I merge(11 as (hl::tl), 12 as (h2,t2)) =

if 0.eq(hl,h2) then hi::merge(tl,t2) else if 0.1t(hl,h2) then hi::merge(tl,12) else h2::merge(11,t2) in set(merge(1,1)) end fun intersect(set 1, set 1) = let fun inter ([] ,1) = [] I inter (1, []) = []

I interdl as (hl::tl), 12 as (h2::t2)) = if 0.eq(hl,h2) then hi::inter(tl,t2) else if 0.1t(hl,h2) then inter(tl,12) else inter(ll,t2)) in set(inter(l,l)) end

end Ответ 4.0.1: local

fun incl(m,n) = if m>n then [] else m::incl(m+l,n) fun move disk ((f, fh::fl), (t, tl), spare) = if not(null tl) andalso (fh:int) > hd tl then error "Illegal move" else (output (std out,

"Move " " (makestring fh) " " from " " f " " to " " t " "\n" ); ((f,fl), (t,fh::tl), spare)) fun transfer(from, to, spare, 1) = move disk (from, to, spare) I transfer(from, to, spare, n) = let val (fl.sl.tl) =

transfer (from, spare, to, n-1) val (f2,t2,s2) = move disk(f1, tl, si) val (s3,t3,f3) = transfer(s2, t2, f2, n-1) in (f3,t3,s3) end



[стр.Начало] [стр.1] [стр.2] [стр.3] [стр.4] [стр.5] [стр.6] [стр.7] [стр.8] [стр.9] [стр.10] [стр.11] [стр.12] [стр.13] [стр.14] [стр.15] [стр.16] [стр.17] [стр.18] [стр.19] [стр.20] [стр.21] [стр.22] [стр.23] [стр.24] [стр.25] [стр.26] [стр.27] [стр.28] [стр.29] [стр.30] [стр.31] [стр.32]