键入的球拍,类型匹配不适合我

时间:2014-11-19 04:53:07

标签: racket typed-racket

我需要这个输入(board-ref (Game-board new-game) (Pos 3 4))才能成真。我一步一步地完成了这个功能,看起来它应该是真的,但由于某种原因,它一直出现错误?谁能帮我解决这个问题?感谢。

(define-type Player (U 'black 'white))

(define-struct Pos
  ([row : Integer]  ;; an integer on the interval [0,7]
   [col : Integer]) ;; an integer on the interval [0,7]
  #:transparent)

(define-struct Board
  ([squares : (Listof (U Player 'none))]) ;; a list of length 64
  #:transparent)

(define-struct Game
  ([board : Board]
   [next  : Player])
  #:transparent)

(: board-ref : Board Pos -> (U Player 'none))
; Returns the current status of a given position on a given board
(define (board-ref b p)
  (cond
    [(or (< (Pos-row p) 0) (< (Pos-col p) 0)) (error "Negative Position value")]
    [(or (> (Pos-row p) 7) (> (Pos-col p) 7)) (error "Position value too large")]
    [else
     (list-ref
      (Board-squares b)
      (+ (* (Pos-row p) 8) (Pos-col p)))]))


(: outflank-hr : Board Player Pos -> Boolean)
; Tests if player can outflank in horizontal right direction
(define (outflank-hr b pl po)
  (local
    {(: path : Board Player Pos -> Boolean)
     (define (path b pl po)
       (match pl
         ['white
          (match po
            [(Pos r c)
             (match (board-ref b po)
               (error #f)
               ('none #f)
               ('white #t)
               ('black (path b pl (Pos r (+ 1 c)))))])]
         ('black
          (match po
            [(Pos r c)
             (match (board-ref b po)
               (error #f)
               ('none #f)
               ('black #t)
               ('white (path b pl (Pos r (+ 1 c)))))]))))}
    (match (board-ref b po)
      [Player #f]
      ['none
       (match pl
         ['black
          [match po
            [(Pos r c)
             (match (board-ref b (Pos r (+ c 1)))
               ['none #f]
               ['black #f]
               ['white (path b 'black (Pos r (+ c 1)))])]]]
         ['white
          [match po
            [(Pos r c)
             (match (board-ref b (Pos r (+ c 1)))
               ['none #f]
               ['white #f]
               ['black (path b 'white (Pos r (+ c 1)))])]]])])))

0 个答案:

没有答案