[julia-users] Re: Default instance of intrinsic type

2014-02-26 Thread Avik Sengupta
Well, there is zero(..) but that is defined only for numeric types julia> zero(Int64) 0 julia> zero(ASCIIString) ERROR: no method convert(Type{ASCIIString}, Int64) in zero at operators.jl:146 julia> zero(Float64) 0.0 On Thursday, 27 February 2014 06:25:39 UTC, Fil Mackay wrote: > > Is there an

[julia-users] Re: Default instance of intrinsic type

2014-02-27 Thread Iain Dunning
Maybe implementing zero for strings could be a good idea... I've implemented it for a few custom types, but theres always been a fairly unambiguous meaning of what it means to be zero. On Thursday, February 27, 2014 2:15:04 AM UTC-5, Avik Sengupta wrote: > > Well, there is zero(..) but that is d

Re: [julia-users] Re: Default instance of intrinsic type

2014-02-27 Thread Stefan Karpinski
Technically the empty string is the 1 of the string monoid. The point being that the correct default value depends on what you're doing. If we were going to have a default value function, it should be a different thing. I'm not convinced that we should encourage default values, however. They strike

Re: [julia-users] Re: Default instance of intrinsic type

2014-02-27 Thread John Myles White
FWIW, we used to have this in DataArrays/DataFrames and it was pretty unpleasant. The trouble is really that any code that calls the default() function is broken for any type that didn’t choose to implement it. So you end up constantly having to create the defaults yourself, while conceding that

Re: [julia-users] Re: Default instance of intrinsic type

2014-02-27 Thread Fil Mackay
On Fri, Feb 28, 2014 at 2:22 AM, Stefan Karpinski wrote: > Technically the empty string is the 1 of the string monoid. The point > being that the correct default value depends on what you're doing. If we > were going to have a default value function, it should be a different > thing. I'm not convi

Re: [julia-users] Re: Default instance of intrinsic type

2014-02-27 Thread Stefan Karpinski
Why is the empty string the zero of the String type? The empty string is the unit of the string monoid, so if anything, one(s::String) should give the empty string. Also, how does this solve any of the problems with a default function that John pointed out? Namely that new custom types generally wo

Re: [julia-users] Re: Default instance of intrinsic type

2014-02-28 Thread Fil Mackay
On Fri, Feb 28, 2014 at 1:47 PM, Stefan Karpinski wrote: > Why is the empty string the zero of the String type? The empty string is > the unit of the string monoid, so if anything, one(s::String) should give > the empty string. > Must zero(::String) != one(::String) ? :) Not sure what else zero

Re: [julia-users] Re: Default instance of intrinsic type

2014-02-28 Thread Toivo Henningsson
Algebraically, the zero string should be such that concatenating (multiplying) it with any string should yield the zero string. There is no such string. So we don't want to mess with the zero function for this purpose (compared to that, even a default function would be better). Why do you want t

Re: [julia-users] Re: Default instance of intrinsic type

2014-02-28 Thread Fil Mackay
On Saturday, March 1, 2014 12:00:29 AM UTC+11, Toivo Henningsson wrote: > > Algebraically, the zero string should be such that concatenating > (multiplying) it with any string should yield the zero string. There is no > such string. > So we don't want to mess with the zero function for this purpo

Re: [julia-users] Re: Default instance of intrinsic type

2014-02-28 Thread Fil Mackay
On Saturday, March 1, 2014 5:39:27 PM UTC+11, Fil Mackay wrote: > > OK - I think there are cross-purposes here. What I'm talking about as > default/zero is getting an instance of a type where the storage bits are > all zero - there is no mathematical/algebraic/monoid angle to this. Ideally > I'd