공순호
가입: 2005년 9월 29일 올린 글: 363 위치: 302동 312-2호
|
올려짐: 2007년6월1일 14:19 주제: 숙제 5-4 추가 설명 및 수정된 뼈대 입니다. |
|
|
숙제 5-4에 대한 설명을 추가해서 드리겠습니다.
우선 아래에서 제공하는 뼈대를 이용해서 숙제를 구현하시기 바랍니다.
교수님께서 주신 숙제와 다른 점은 pp의 타입이 pp : box -> unit으로 변경되었고
몇몇 오류들이 수정되었습니다.
pp의 의미는
1. 임의의 box에 대해서 NW, NE, SE, SW 순으로 box의 내용을 출력하고
2. 기본 박스에 대해서는 "방향:디자인 "으로 출력해주는 것 입니다.
pp의 출력은 2차원으로 출력하는 것이 아닌, 위의 순서에 의해서 1차원으로 출력되도록 해주시면 됩니다. 예는 아래의 그림을 참고하시기 바랍니다.
아래에서 rotate의 의미에 대해서 질문해주셨는데, 다음 아래의 그림을 보시면 이해가 되실 것으로 생각합니다.
코드: |
type design = TURTLE | WAVE | DRAGON | KAIST
type orientation = NW | NE | SE | SW
type box = BOX of orientation * design | GLUED of box * box * box * box
signature FRAME =
sig
val box : box
val rotate : box -> box
val pp : box -> unit
end
functor BasicFrame(Design: sig val pattern : design end) : FRAME =
struct
exception NON_BASIC_BOX
val box = ...
val rotate = ...
fun pp (BOX(o,d)) =
let
fun print_o NW = print_string "NW"
| print_o NE = print_string "NE"
| print_o SE = print_string "SE"
| print_o SW = print_string "SW"
fun print_d TURTLE = print_string "T"
| print_d WAVE = print_string "W"
| print_d DRAGON = print_string "D"
| print_d KAIST = print_string "K"
in
print_o o;
print_string ":";
print_d d;
print_string " "
end
| pp _ = raise NON_BASIC_BOX
end
functor Rotate(Box: FRAME) : FRAME =
struct
val box = ...
val rotate = ...
val pp = ...
end
functor Glue(
Nw: FRAME,
Ne: FRAME,
Se: FRAME,
Sw: FRAME) : FRAME =
struct
exception NON_GLUED_BOX
val box = ...
val rotate = ...
fun pp GLUED(nw, ne, se, sw) =
Nw.pp nw;
Ne.pp ne;
Se.pp se;
Sw.pp sw
| pp _ = raise NON_GLUED_BOX
end
|
다음과 같은 코드에 대해서, 아래와 같이 작동하도록 구현하시면 됩니다.
코드: |
structure A = BasicFrame(struct val pattern = TURTLE end)
structure B = BasicFrame(struct val pattern = WAVE end)
structure A' = Rotate(A) (* another block rotated by 90 degrees clockwise *)
structure A'' = Rotate(A') (* another block rotated by 90 degrees clockwise *)
structure B' = Rotate(B) (* another block rotated by 90 degrees clockwise *)
structure B'' = Rotate(B') (* another block rotated by 90 degrees clockwise *)
structure BigA = Glue(A,B,A',B')
structure BigB = Glue(A, A'', B, B'')
structure BigA' = Rotate(BigA)
structure BigB' = Rotate(BigB)
structure M = Glue(BigA, BigB, BigA', BigB')
val bluePrint = M.pp M.box
|
그림의 맨 마지막에 나온
인용: |
NW:T NW:W NE:T NE:W NW:T SE:T NW:W SE:W SE:W NE:T NE:W SE:T SW:W NE:T SW:T NE:W
|
이 M.pp M.box의 결과 입니다. _________________ - soon@ropas |
|