@David, What doesn't work for you? Do you mean you're getting the same 
error?

On Monday, 15 June 2015 08:55:07 UTC+5:30, Ranjan Anantharaman wrote:
>
> But Simon, Julia allows me to define this composite type. There just 
> doesn't seem to be any obvious way to create an object of that type. 
>
> Additionally, writing the type that way results in the same error.
>
> On Sunday, 14 June 2015 17:10:56 UTC+5:30, Simon Danisch wrote:
>>
>> Julia is not object oriented, so you only put constructors inside the 
>> type definition, which are then inner constructors.
>> Inner constructors overwrite the default constructor, so the function 
>> boss() replaces foo(::Int64).
>> What you probably want is:
>> type foo
>>   a::Int
>> end
>> function boss(::foo)
>>     println("Hey, boss!")
>> end
>> Am Sonntag, 14. Juni 2015 13:26:28 UTC+2 schrieb Ranjan Anantharaman:
>>>
>>> Hello,
>>>
>>> How do I initialize this composite type in Julia?
>>>
>>> type foo
>>>   a::Int64
>>>   function boss()
>>>     println("Hey, boss!")
>>>   end
>>> end
>>>
>>> If I do f = foo(1), then I get the following error: 
>>>
>>> ERROR: MethodError: `convert` has no method matching 
>>> convert(::Type{foo}, ::Int64)
>>> This may have arisen from a call to the constructor foo(...),
>>> since type constructors fall back to convert methods.
>>> Closest candidates are:
>>>   call{T}(::Type{T}, ::Any)
>>>   convert{T}(::Type{T}, ::T)
>>>  in call at base.jl:40
>>>
>>> How do I create an object of type foo?
>>>
>>> Thanks in advance.
>>>
>>

Reply via email to