Where I'd expect the nums argument to always be Int[] (or maybe a List of objects that inherit from Int), or the compiler should complain about type mismatch on work(b).
brianSat 12 May 2018
Hi dubek, welcome to Fantom!
Typically with map you are creating a new list (or map) of a different type. The runtime will type the result based on your closure's return type:
Another thing is that the compiler happily allowed me to pass such a sys::Obj?[] variable to function which takes an Int[] parameter
Unlike Java or more classical statically typed languages, Fantom only makes it a compile time error when it knows for sure that the type is wrong. If the type could be right, but would require a cast in Java or C# then the compiler will allow it and use an implicit casting. See docLang::TypeSystem#implicitCasts for more details. In general we find this to be a very pragmatic approach for the type system
SlimerDudeSun 13 May 2018
-- deleted --
SlimerDudeSun 13 May 2018
Hi Dubek,
I'm reading 2 queries in your post:
1). Type info lost from it-blocks
Yes, the return type is lost from it-blocks / implicit functions.
This is a limitation of the compiler, for it can not truly know (in every situation) what is being returned until runtime. Because of this, it simply defaults to Obj?.
Agreed, for simple statements the compiler could be a bit cleverer. But as you stated, it can be worked around by fully qualifing the function parameters.
Note there are a couple of other forum posts related to this:
Yes, the Fantom compiler is a bit looser than compilers for other statically typed languages and this is one of the areas where Fantom excels.
As far as the compilier is concerned, if something could work then it assumes it does work!
It extends some trust to the programmer and prevents you from having to down cast everywhere - it really cuts down on the amount of code you have to write.
dubek Sat 12 May 2018
I'm new to Fantom, so excuse me if this report is just a misunderstanding.
I found that using an it-block with
map
loses the type of the new returned collection (List or Map). For example:The same happens with Maps:
Using a full closure (instead of the it-block) solves the issue:
Another thing is that the compiler happily allowed me to pass such a
sys::Obj?[]
variable to function which takes anInt[]
parameter:Running this gives:
Where I'd expect the
nums
argument to always beInt[]
(or maybe a List of objects that inherit fromInt
), or the compiler should complain about type mismatch onwork(b)
.brian Sat 12 May 2018
Hi dubek, welcome to Fantom!
Typically with map you are creating a new list (or map) of a different type. The runtime will type the result based on your closure's return type:
Unlike Java or more classical statically typed languages, Fantom only makes it a compile time error when it knows for sure that the type is wrong. If the type could be right, but would require a cast in Java or C# then the compiler will allow it and use an implicit casting. See docLang::TypeSystem#implicitCasts for more details. In general we find this to be a very pragmatic approach for the type system
SlimerDude Sun 13 May 2018
-- deleted --
SlimerDude Sun 13 May 2018
Hi Dubek,
I'm reading 2 queries in your post:
1). Type info lost from it-blocks
Yes, the return type is lost from it-blocks / implicit functions.
This is a limitation of the compiler, for it can not truly know (in every situation) what is being returned until runtime. Because of this, it simply defaults to
Obj?
.Agreed, for simple statements the compiler could be a bit cleverer. But as you stated, it can be worked around by fully qualifing the function parameters.
Note there are a couple of other forum posts related to this:
2). The un-strict compiler
Yes, the Fantom compiler is a bit looser than compilers for other statically typed languages and this is one of the areas where Fantom excels.
As far as the compilier is concerned, if something could work then it assumes it does work!
It extends some trust to the programmer and prevents you from having to down cast everywhere - it really cuts down on the amount of code you have to write.
I give an example and say more here: http://www.alienfactory.co.uk/articles/fantom-the-developers-choice#typeInference
I hope this helps, and let us know how you're getting on with that Fantom Lisp implementation!
Steve.
dubek Mon 4 Jun 2018
Just an update: the Mal (Make-a-Lisp) implementation is done and merged! The code is at https://github.com/kanaka/mal/tree/master/fantom .