嗨,我正在学习如何使用球拍提供的日志记录工具。我编写了以下代码来了解事情的运作方式。
#lang racket
(define list-logger (make-logger 'list-logger))
;;(: log-debug (String Symbol -> Void))
(define (log-debug message name)
(log-message list-logger 'debug message name))
;;(: sum-a-list ((Listof Integer) (Integer Integer -> Integer) -> Integer))
(define (sum-a-list l operator)
(begin (log-debug (format "Message ~a" l) 'sum-a-list)
(cond [(empty? l) 0]
[else (operator (first l) (sum-a-list (rest l) operator))])))
(define recevier (make-log-receiver list-logger 'debug))
;;(: main (-> Any))
(define (main)
(begin (sum-a-list (list 1 2 3 4 5 6 7 8) +)
;; (: logger (-> Any)
(define (logger)
(let ([msg (sync recevier)])
(match msg
[(vector level m data x) (begin (printf "~a: ~a\n" level m)
(logger))]
[else #f ])))
(logger)))
上面的代码可以编译并且工作正常。当我使用打字球拍而不是球拍时,问题就出现了。对于相同的代码(带有类型注释和类型/球拍),我得到一个类型检查器错误。
;; code with typed racket and type annotations
#lang typed/racket
(define list-logger (make-logger 'list-logger))
(: log-debug (String Symbol -> Void))
(define (log-debug message name)
(log-message list-logger 'debug message name))
(: sum-a-list ((Listof Integer) (Integer Integer -> Integer) -> Integer))
(define (sum-a-list l operator)
(begin (log-debug (format "Message ~a" l) 'sum-a-list)
(cond [(empty? l) 0]
[else (operator (first l) (sum-a-list (rest l) operator))])))
(define recevier (make-log-receiver list-logger 'debug))
(: main (-> Any))
(define (main)
(begin (sum-a-list (list 1 2 3 4 5 6 7 8) +)
(: logger (-> Any))
(define (logger)
(let ([msg (sync recevier)])
(match msg
[(vector level m data x) (begin (printf "~a: ~a\n" level m)
(logger))]
[else #f ])))
(logger)))
;; type checker error: Type Checker: untyped identifier sync imported from module <typed/racket> in: sync
我想在我的项目中使用类型化的球拍来实现日志记录支持。我不知道如何解决这个错误。请帮我解决这个问题。谢谢!