suggestions
suggestions copied to clipboard
Simpler single constructor type definition
How about accepting:
pub type Cat(name: String, cuteness: Int)
As the equivalent to:
pub type Cat {
Cat(name: String, cuteness: Int)
}
Gleam aims to not have multiple ways of writing the same thing, so this is something I'm not eager to add. However if this proves popular we can explore a concise sugar. Let’s see what people think
I would like this
I agree that it's a bit verbose, but the shorthand would be ambiguous with type parameters:
pub type Box(a) {
Box(x: a)
}
// ???
pub type Box(a)(x: a)
A C-like struct maybe? This would be very confusing though and you'd have to peek for the colon to know it's not a union...
pub type Cat {
name: String,
cuteness: Int
}
pub type Box(a) {
x: a
}
Gleam aims to not have multiple ways of writing the same thing, so this is something I'm not eager to add.
I wholeheartedly agree with this principle, though for this particular scenario I don't see a reason to ever use the longer form for a single-case union if the short version existed. This could even be an auto-fix for the formatter...
Having an easy (and single-line) way to define records would encourage their use for smaller things which helps with code clarity.
pub type Cat { Cat(name: String, cuteness: Int) }
I'd sooner return a tuple than type out the above record for some internal function result.
After more thought I think type Cat(name: String, cuteness: Int)
would be perfect (if the parameter type thing can be dealt with...)
I'm not dead against having a concise syntax for this! Let's collect ideas for what it could be and at a later date we can see where we are.