Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coerce numeric types #3345

Closed
trans opened this issue Sep 25, 2016 · 6 comments
Closed

Coerce numeric types #3345

trans opened this issue Sep 25, 2016 · 6 comments

Comments

@trans
Copy link

trans commented Sep 25, 2016

Take simple example:

def fib(n : Int64)
  ...
end
puts fib(42) 

Produces the error:

Error in ./ex.cr:11: no overload matches 'fib' with type Int32
Overloads are:
 - fib(n : Int64)

puts fib(42)
     ^~~

It must be possible for Crystal to coerce 42 into Int64 in cases like this. The error message makes it clear it knows what's up. Basically any IntX passed to an IntY parameter where X < Y, should be coercible by the compiler.

It would nice b/c it would let us remove a fair but of extra boilerplate in the form of _i64, and the like.

Although perhaps there is better/more appropriate way to remedy this?

@ozra
Copy link
Contributor

ozra commented Sep 25, 2016

Reads of interest: #567, #2995, #1778, etc.

@ysbaddaden
Copy link
Contributor

Duplicate of #2995.

@refi64
Copy link
Contributor

refi64 commented Sep 25, 2016

@trans Hey, you're back!

@trans
Copy link
Author

trans commented Sep 25, 2016

@kirbyfan64 Hi! Yep, I've been heehawing about what new language to adopt for awhile. I narrowed it down just the other day when I decided I wanted a compiled language, nothing dynamic and no runtime VMs. That helped eliminated a few (otherwise good) choices like Clojure and Elixir, and left me with basically five options: Go, Rust, Julia, Swift and Crystal. The first two I decided are at a level a bit lower than I want to be working. For the moment Julia and Swift are still on my radar, but I need to get a project moving and I can leverage my Ruby skills, so Crystal.

P.S. Holy smokes, talk about serendipity. The project I just started working on (with Crystal) is a site/blog generator. One of the options I was thinking of adding was dynamic page generation from JSON (as an alternative to full static generation). Well bite my code, I just checked out your blog and the first post I see explains how that's exactly what you are doing!!!!!!!!! Hot damn. Could I get access to your source so I can use it in my project? With any luck that'll save me a lot of time. And in exchange I'll fix your RSS problem :-)

@refi64
Copy link
Contributor

refi64 commented Sep 26, 2016

@trans

For the moment Julia and Swift are still on my radar

Uhh...doesn't Julia use a runtime VM?

P.S. Holy smokes, talk about serendipity. ...

:D FYI, we might want to discuss this off the issue tracker...

And in exchange I'll fix your RSS problem :-)

Wow, I just have to see this.

@trans
Copy link
Author

trans commented Sep 26, 2016

Okay, email me (my address is listed on my github profile. I couldn't find yours.) I'm busy the rest of this week but should have time next week. And, oh yea, https://github.com/trans/brite.cr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants