4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Nimで変数の型名を確認する

Posted at

はじめに

Nimは型推論してくれるので、型を意識しなくても割と使えるど
いざ関数定義とかで型を書く必要が出てきたときに困ったりしてた。

で、どうやんの?

typeでOK。

type X = object of RootObj                                                      
type RefX = ref object of RootObj                                               
proc someFunc(n: int): string = $(n * 2)
echo (new X).type                                                               
echo X().type                                                                   
echo (new RefX).type                                                            
echo RefX().type                                                                
echo 3.type                                                                     
echo 3'i8.type                                                                  
echo 3'u.type                                                                   
echo 3'u32.type                                                                 
echo "hello".type                                                               
echo 'a'.type                                                                   
echo (42, 'c', "string").type                                                   
echo someFunc.type
実行結果
ref X
X
RefX
RefX
int
int8
uint
uint32
string
char
(int, char, string)
proc (n: int): string{.noSideEffect, gcsafe, locks: 0.}

以上〜。

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?