|
|
이전 주제 보기 :: 다음 주제 보기 |
글쓴이 |
메시지 |
tmdcjf910
가입: 2013년 10월 1일 올린 글: 9
|
올려짐: 2013년11월25일 20:26 주제: 6-7 질문이요! |
|
|
이제 제출기한도 끝났고 하니 실패한 코드 함 봐주세요..
exception TODO
type crazy2 =
| NIL
| ZERO of crazy2
| ONE of crazy2
| MONE of crazy2
let rec first2 (c:crazy2): int =
match c with
|NIL -> 0
|(ZERO _) -> 0
|(ONE _) -> 1
|(MONE _) -> -1
let rec second2 (c:crazy2) : crazy2 =
match c with
|NIL -> NIL
|(ZERO b) -> b
|(ONE b) -> b
|(MONE b) -> b
let rec crazy2add1 (a: crazy2) (b: crazy2) (c: crazy2) : crazy2 =
match (a, b, c) with
|NIL, NIL, NIL -> NIL
|NIL, NIL, a -> a
|NIL, a, NIL -> a
|a, NIL, NIL -> a
|a, b, c ->
if (first2 a) + (first2 b) + (first2 c) = 3
then (ONE (crazy2add1 (second2 a) (second2 b) (ONE NIL)))
else if (first2 a) + (first2 b) + (first2 c) = 2
then (ZERO (crazy2add1 (second2 a) (second2 b) (ONE NIL)))
else if (first2 a) + (first2 b) + (first2 c) = 1
then (ONE (crazy2add1 (second2 a) (second2 b) NIL))
else if (first2 a) + (first2 b) + (first2 c) = 0
then (ZERO (crazy2add1 (second2 a) (second2 b) NIL))
else if (first2 a) + (first2 b) + (first2 c) = -1
then (MONE (crazy2add1 (second2 a) (second2 b) NIL))
else if (first2 a) + (first2 b) + (first2 c) = -2
then (ZERO (crazy2add1 (second2 a) (second2 b) (MONE NIL)))
else if (first2 a) + (first2 b) + (first2 c) = -3
then (MONE (crazy2add1 (second2 a) (second2 b) (MONE NIL)))
왜 crazy2add1에서 -> crazy2로 지정까지 해줬는데 왜 unit을 찾을까요?
에러는 The variant type unit has no constructor MONE이라고 뜹니다. |
|
위로 |
|
|
강지훈
가입: 2008년 9월 2일 올린 글: 291 위치: 302동 312-2호
|
올려짐: 2013년11월27일 16:08 주제: |
|
|
제 생각에 마지막에
"else if ...
then ..."
으로 끝나는데,
"else"
를 추가해줘야 할 것 같습니다.
if a then b else c가 옳은 구문이고,
if a then b는 옳은 구문이 아닙니다. _________________ 강지훈
프로그래밍의 원리 조교
Jeehoon Kang
TA, Principles of Programming |
|
위로 |
|
|
|
|
새로운 주제를 올릴 수 없습니다 답글을 올릴 수 없습니다 주제를 수정할 수 없습니다 올린 글을 삭제할 수 없습니다 투표를 할 수 없습니다
|
Powered by phpBB 2.0.21-7 (Debian) © 2001, 2005 phpBB Group Translated by kss & drssay
|