You might have figured this out by now, if you have a parameterized family
of types Degree{T}, there is no unparameterized version available, so you
either have to

1) provide a default constructor which creates the proper parameterized type

Degree{T<:Number}(d::T) = Degree{T}(d)

This is a parameterized *function* taking a parameter d, from which the
type T is inferred, and calls the constructor for *type* Degree{T} (the T is
part of the type).  The function can then be called with Degree(num).

Or, you can

2)  call the type constructor directly (always using Degree{T}(d)).  In
your code, this would be

*{T<:Number}(num::T, s::DegreeSign) = Degree{T}(num)


Cheers,
    Kevin


On Saturday, February 15, 2014, Johan Sigfrids <[email protected]>
wrote:

> Forget what I've said. Apparently it is my constructor that isn't working
> on variable. Sorry for the noise.
>
> On Saturday, February 15, 2014 1:15:53 PM UTC+2, Johan Sigfrids wrote:
>>
>> Hmm. Or maybe neither work and the for loop is only hiding the error?
>>
>> On Saturday, February 15, 2014 1:11:36 PM UTC+2, Johan Sigfrids wrote:
>>>
>>> I've been playing with a Degree type in Julia, and have set it up so I
>>> can use ° to construct Degrees:
>>>
>>> module Degrees
>>>
>>> export Degree, °
>>>
>>> immutable Degree{T<:Number} <:Number
>>>     d::T
>>> end
>>>
>>> immutable DegreeSign end
>>>
>>> const ° = DegreeSign()
>>>
>>> *(num::Number, s::DegreeSign) = Degree(num)
>>>
>>> Base.show(io::IO, d::Degree) = print(io, "$(d.d)°")
>>>
>>> end
>>>
>>> I can successfully construct a array of Degrees with a for loop like so:
>>>
>>> for i in 1:10
>>>     i°
>>> end
>>>
>>> But the same thing doesn't work in a comprehension:
>>>
>>> [ i° for i in 1:10]
>>>
>>> This leads to a error complaining that `i° not defined`. It sounds to me
>>> like it is evaluating `i°` before i has a value assigned to it. What's
>>> going on here?
>>>
>>

Reply via email to