Is it possible to specify the type of a function/method's return value? 
That is, if it were possible to define foo() so that we knew it would 
return an Int64, say, then 1) we could guarantee type stability, and 2) we 
could also throw a warning or error if it returned something else.

On Monday, July 20, 2015 at 1:07:30 PM UTC-7, Patrick O'Leary wrote:
>
> That addresses one class of problem, but the two problems I see from Kaj's 
> original post wouldn't be addressed: one, that the incorrect return value 
> from foo() is silently accepted in the no-destructuring case, and two, that 
> when destructuring, you still get an error message about iteration, even 
> though it's not clear what is failing to be iterated.
>
> On Monday, July 20, 2015 at 2:36:06 PM UTC-5, Simon Danisch wrote:
>>
>> This could actually be solved by having something like this in base:
>>
>> start{T}(x::T) = error("$T is not iterable. Try implementing start(::$T), 
>> done(::$T, state), next(::$T, state)")
>>
>> The basic problem here is, that Julia has weakly enforced interfaces, 
>> which often ends in no method errors instead of something meaningfull for 
>> people who don't know the implicit interfaces.
>>
>> Am Montag, 20. Juli 2015 21:09:00 UTC+2 schrieb Kaj Wiik:
>>>
>>> I started to get a strange error while debugging my code, here's a 
>>> simplified example:
>>>
>>> julia> function foo(a)
>>>            println("foo..")
>>>        end
>>> foo (generic function with 1 method)
>>>
>>> julia> a = foo(2)
>>> foo..
>>>
>>> julia> a,b = foo(2)
>>> foo..
>>> ERROR: `start` has no method matching start(::Nothing)
>>>
>>>
>>> So, the problem was a missing return value, it is strange that missing 
>>> one value did not give error but two values.... It took a quite long time 
>>> to track this down. Perhaps a bit more informative error message would be 
>>> possible...?
>>>
>>> Cheers,
>>> Kaj
>>>
>>>

Reply via email to