开发者

Can one create Sized Types in Scala?

开发者 https://www.devze.com 2022-12-26 20:54 出处:网络
Is it possible to create types like e.g. String(20) in scala? The aim would be to have compiler checks for things like:

Is it possible to create types like e.g. String(20) in scala?

The aim would be to have compiler checks for things like:

a: String(20) 
b: String(30)
a = b; // throws开发者_如何学编程 a compiler exception when no implicit conversion is available
b= a; // works just fine

Note: It doesn't need to be/named String


Yes, it is possible, using Church Numerals encoding. Jim McBeath has a good series of blogs relating to that. Start here, but keep looking for other references on the Internet. He wasn't the only one to talk about it, nor was this his only post.

It isn't, however, very much practical.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号