Thanks, that's something to look at.

On Wednesday, December 9, 2015 at 9:28:13 AM UTC-5, Eric Forgy wrote:
>
> How about this?
>
>
> https://github.com/JuliaLang/julia/blob/2d821670d2516cd38b51710b07b3eb18f191cd1b/base/multimedia.jl
>
>
> On Wednesday, December 9, 2015 at 10:22:06 PM UTC+8, milktrader wrote:
>>
>> I'd like a somewhat clever example (or boring one for that matter) that 
>> shows:
>>
>> 1. How to create an instance of a singleton type
>>
>> 2. How to write methods that use this type in a meaningful way.
>>
>> 3. How it's used in Base code (I seem to recall Void is a singleton type)
>>
>> On Wednesday, December 9, 2015 at 9:02:31 AM UTC-5, tshort wrote:
>>>
>>> I'm not sure what you want, either. How about this?
>>>
>>> julia> type BadInt{X} end
>>>
>>> julia> BadInt{3}()
>>> BadInt{3}()
>>>
>>> julia> f{X}(::Type{BadInt{X}}, y) = X - y
>>> f (generic function with 1 method)
>>>
>>> julia> f(BadInt{10}, 3)
>>> 7
>>>
>>> julia> f{X}(::BadInt{X}, y) = X - y
>>> f (generic function with 2 methods)
>>>
>>> julia> f(BadInt{10}(), 3)
>>> 7
>>>
>>>
>>> On Wed, Dec 9, 2015 at 8:56 AM, Eric Forgy <eric....@gmail.com> wrote:
>>>
>>>> Not sure I follow, but does this help?
>>>>
>>>> julia> type BadInt
>>>>        end
>>>>
>>>> julia> bi = BadInt()
>>>> BadInt()
>>>>
>>>> julia> typeof(bi)
>>>> BadInt
>>>>
>>>>
>>>> On Wednesday, December 9, 2015 at 9:46:01 PM UTC+8, milktrader wrote:
>>>>>
>>>>> How do you create an instance of type BadInt then?
>>>>>
>>>>> On Wednesday, December 9, 2015 at 7:01:25 AM UTC-5, milktrader wrote:
>>>>>>
>>>>>> Trying to wrap my mind around singleton types to see if they might be 
>>>>>> useful for something I'm working on, but running into some confusion. 
>>>>>> Here 
>>>>>> is an example that I started working with:
>>>>>>
>>>>>> julia> type BadInt
>>>>>>        end
>>>>>>
>>>>>> julia> import Base.+
>>>>>>
>>>>>> julia> +(x::BadInt, y::Int64) = x - y
>>>>>> + (generic function with 172 methods)
>>>>>>
>>>>>> julia> BadInt() = 2
>>>>>> BadInt
>>>>>>
>>>>>> julia> BadInt + 2
>>>>>> ERROR: MethodError: `+` has no method matching +(::Type{BadInt}, 
>>>>>> ::Int64)
>>>>>> Closest candidates are:
>>>>>>   +(::Any, ::Any, ::Any, ::Any...)
>>>>>>   +(::Int64, ::Int64)
>>>>>>   +(::Complex{Bool}, ::Real)
>>>>>>   ...
>>>>>>
>>>>>> As I understand, a singleton type can only take on a single value. 
>>>>>> What's the utility in supporting this?
>>>>>>
>>>>>
>>>

Reply via email to