2016-08-29 8 views
3

型付きラケットに構造体を定義するとき、私はもはやprop:procedureを使用できません。通常のラケットでは、私のような何かを行うことができます。型付きラケットにprop:手続きを適用できません

(struct profile-unit (a t c g) 
    #:property prop:procedure (thunk* 12)) 

(define t (profile-unit .1 .1 .2 .6)) 
(t) 
> 12 

をしかし、私は型付け/ラケットでそれをしようとしたとき、私は型チェックのエラーが表示されます。

(struct profile-unit ([a : Real] [t : Real] [c : Real] [g : Real]) 
    #:property prop:procedure (thunk* 12)) 
(t) 
> Type Checker: Cannot apply expression of type profile-unit, since it is not a function type in: (t) 

は、入力されたラケットでこのプロパティを定義する別の方法はあります?

+0

以前の「#lang typed/racket」では以前と同じように機能しませんでしたか? – Sylwester

+0

'thunk *'は型付きラケットのtypecheckも今のところは –

答えて

3

@Leif Asersen氏によると、#:property structオプションは型付きラケットでは機能しません。

prop:procedureの特別な場合は、define-struct/execフォームを使用できます。

#lang typed/racket 

(define-struct/exec profile-unit ([a : Real] [t : Real] [c : Real] [g : Real]) 
    [(λ (this) 12) : (profile-unit -> Any)]) 

(define t (profile-unit .1 .1 .2 .6)) 
(t) ; 12 
+1

ああ、それは気の利いたものです。 –

2

typed/racketの構造体には、#:propertyフィールドを含めることはできません。ジェネリックもサポートしていません。

このように呼び出すこともできるという事実は私のバグのようです。あなたが本当にかかわらず、機能のような構造体を呼び出したいならば

、あなたが入力したコードにそれを得るために#:structrequire/typedを使用して、型指定されていないコードでそれを定義し、手順にそれを回すためにcastを使用することによってそれを行うことができます。例:この例では

#lang typed/racket 

(module foo racket 
    (provide (struct-out profile-unit) 
      make-profile-unit) 

    (struct profile-unit (a t c g) 
    #:property prop:procedure (thunk* 12)) 
    (define make-profile-unit profile-unit) 
    ((profile-unit 1 2 3 4))) 

(require/typed 'foo 
       [#:struct profile-unit ([a : Real] 
             [t : Real] 
             [c : Real] 
             [g : Real])]) 

((cast (profile-unit 1 2 3 4) (-> Any))) 

profile-unitプロシージャと呼ばれています。

関連する問題