rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

null (or none) and anonymous sumtypes

Open igotfr opened this issue 4 years ago • 2 comments

mut i := (u16 | null)(78)

i = (u16 | null)(49)
// or
i = u16(49)

i = (u16 | null)(null)
// or
i = null

// ?u16 is equivalent to u16 | null, so the above is equivalent to:
mut i := ?u16(78)

i = ?u16(49)
// or
i = u16(49)

i = ?u16(null)
// or
i = null

// or
mut i := u16_null(78)
i = u16_null(49)
i = u16_null(null)
mut s := (string | null)('bagaço')

s = (string | null)('sebo')
// or
s = 'sebo'

s = (string | null)(null)
// or
s = null

// ?string is equivalent to string | null, so the above is equivalent to:
mut s := ?string('bagaço')
// or
mut s := ?'bagaço'

s = ?string('sebo')
// or
s = ?'sebo'
// or
s = 'sebo'

s = ?string(null)
// or
s = null

// or
mut s := string_null('bagaço')
s = string_null('sebo')
s = string_null(null)
struct User {
  name string
  password string
}

mut u := (User | null){name: 'Cleosmar', password: 'easy'}

u = (User | null){name: 'Rodinei', password: 'hard'}
// or
u = User{name: 'Rodinei', password: 'hard'}

u = (User | null){null}
// or
u = null

// ?User is equivalent to User | null, so the above is equivalent to:
mut u := ?User{name: 'Cleosmar', password: 'easy'}

u = ?User{name: 'Rodinei', password: 'hard'}
// or
u = User{name: 'Rodinei', password: 'hard'}

u = ?User{null}
// or
u = null

igotfr avatar Aug 19 '21 03:08 igotfr

related: https://github.com/vlang/v/discussions/11913 https://github.com/vlang/v/issues/9598 https://github.com/vlang/v/issues/11293 https://github.com/vlang/v/pull/9567 https://github.com/vlang/v/pull/10795 https://github.com/vlang/v/discussions/11880 https://github.com/vlang/v/discussions/11834 https://github.com/vlang/v/issues/10239 https://github.com/vlang/v/pull/9793 https://github.com/vlang/v/issues/9761 https://github.com/vlang/v/issues/12029#issuecomment-934997309 https://github.com/vlang/v/discussions/7610#discussioncomment-643342 https://github.com/vlang/v/discussions/7610#discussioncomment-257982 https://github.com/vlang/v/issues/9843 https://github.com/vlang/rfcs/pull/7

igotfr avatar Oct 13 '21 18:10 igotfr

The most sound solution would be:

noreturn / Void : has no possible value none / Unit : has 1 possible value

iacore avatar Oct 06 '22 18:10 iacore