Raku의 type — 타입 제약을 돌려주는 곳들
Raku의 type — 타입 제약을 돌려주는 곳들
type은 Raku에서 '어떤 종류(타입)인가'를 돌려주는 이름으로 여기저기 쓰여요. 속성·파라미터·에러 객체가 가진 타입 제약을 확인하고 싶을 때, 각 타입마다 저마다의 type 메서드가 존재해요. 하나씩 살펴볼게요.
X::Bind::Slice — 슬라이스 바인딩 대상의 타입 객체
method type(X::Bind::Slice:D:)
슬라이스 바인딩(slice-bind)을 시도한 대상의 타입 객체를 돌려줘요. 예를 들어 Array, List, Hash 등이에요.
RakuAST::Doc::Block — 블록의 타입
say "type = $block.type()";
블록의 타입을 돌려줘요.
Attribute — 속성의 타입 제약
method type(Attribute:D: --> Mu)
속성의 타입 제약을 돌려줘요.
class TypeHouse {
has Int @.array;
has $!scalar;
has @.mystery;
}
my @types = TypeHouse.^attributes(:local)[0..2];
for 0..2 { say @types[$_].type }
# OUTPUT: «(Positional[Int])
# (Mu)
# (Positional)»
Int @.array는 Positional[Int], 타입 제약이 없는 $!scalar는 Mu, @.mystery는 Positional로 돌아와요.
Parameter — 파라미터의 명목 타입 제약
파라미터의 명목(nominal) 타입 제약을 돌려줘요.
Pod::FormattingCode
method type(--> Mu)
X::Does::TypeObject — 롤을 섞으려던 타입 객체
method type(X::Does::TypeObject:D: --> Mu:U)
코드가 롤(role)을 믹스인하려다 실패한 대상 타입 객체를 돌려줘요.
본문
X::Bind::Slice.type: 슬라이스 바인딩 대상의 타입 객체.Attribute.type: 속성의 타입 제약.Parameter.type: 파라미터의 명목 타입 제약.X::Does::TypeObject.type: 롤 믹스인을 시도한 타입 객체.RakuAST::Doc::Block.type: 블록의 타입.