Live data from Hacker News

Show HN: The Sage Programming Language

github.com

21–30 of 32 posts

Re: Show HN: The Sage Programming Language

#23
post #8

FYI, Sage is also the name of a mathematical programming language: https://www.sagemath.org/

I used SageMath for my masters. It was a life saver.

I'll have to check it out and reimplement it's good features for THIS Sage hahaha

Re: Show HN: The Sage Programming Language

#24
One thing I like is exploring the structural typing.

However I am confused if the enum's are structural or nominal. It seems necessary to state which enum a variant comes from, like `Direction of South` (for that matter it seems the same is true when constructing structs?). Can you cast enum values to a wider enum type? Or combine different enum values (e.g. through branching - the return of `match`) to construct a value of a wider enum?

Re: Show HN: The Sage Programming Language

#25

One thing I like is exploring the structural typing. However I am confused if the enum's are structural or nominal. It seems necessary to state which enum a variant comes from, like `Direction of South` (for that matter it seems the same is true when constructing structs?). Can you cast enum values to a wider enum type? Or combine different enum values (e.g. through branching - the return of `match`) to construct a v…

Hello, thanks for the great question! Yes, you do have to specify where a variant comes from, but it doesn't have to be nominal at all! Here's an example:

``` enum Option {Some(T), Nothing}

// Create a value with an inline type that doesn't use the nominal `Option`

let opt1 = enum {Some(Int), Nothing} of Some(5);

// Define a second option value, which is assigned with the first

let opt2: Option = opt1;

// Print the result

println(opt2); ```

You can create a variant of an inline `enum` type, and then typecheck it against another structurally equal type if you so choose!

I hope this example properly illustrates how powerful the structural type-checking is with enums!

Re: Show HN: The Sage Programming Language

#26

One thing I like is exploring the structural typing. However I am confused if the enum's are structural or nominal. It seems necessary to state which enum a variant comes from, like `Direction of South` (for that matter it seems the same is true when constructing structs?). Can you cast enum values to a wider enum type? Or combine different enum values (e.g. through branching - the return of `match`) to construct a v…

Hello, thanks for the great question! Yes, you do have to specify where a variant comes from, but it doesn't have to be nominal at all! Here's an example: ``` enum Option {Some(T), Nothing} // Create a value with an inline type that doesn't use the nominal `Option` let opt1 = enum {Some(Int), Nothing} of Some(5); // Define a second option value, which is assigned with the first let opt2: Option = opt1; // Print the r…

That's an interesting approach. So the variant name itself doesn't bear the type information but should be uniquely resolved in the type check time, right? It will be pretty much optimal unless you are doing metaprogramming stuffs.

Re: Show HN: The Sage Programming Language

#27
post #8

FYI, Sage is also the name of a mathematical programming language: https://www.sagemath.org/

Thank you!! Sage will eventually change its name (I just recently found out about this), but I haven't had time to come up with a good replacement name and make art + quippy sayings for it yet! :) I might just go with a completely made up word to avoid any trademarks entirely haha

I was surprised to find no associated programming languages for sumac and bay (leaf).

Re: Show HN: The Sage Programming Language

#29

Earlier quoted context omitted.

Hello, thanks for the great question! Yes, you do have to specify where a variant comes from, but it doesn't have to be nominal at all! Here's an example: ``` enum Option {Some(T), Nothing} // Create a value with an inline type that doesn't use the nominal `Option` let opt1 = enum {Some(Int), Nothing} of Some(5); // Define a second option value, which is assigned with the first let opt2: Option = opt1; // Print the r…

That's an interesting approach. So the variant name itself doesn't bear the type information but should be uniquely resolved in the type check time, right? It will be pretty much optimal unless you are doing metaprogramming stuffs.

That's right! I think it's a good balance between giving the typechecker the info it needs, but also being flexible in how you can supply it!

Re: Show HN: The Sage Programming Language

#30

One thing I like is exploring the structural typing. However I am confused if the enum's are structural or nominal. It seems necessary to state which enum a variant comes from, like `Direction of South` (for that matter it seems the same is true when constructing structs?). Can you cast enum values to a wider enum type? Or combine different enum values (e.g. through branching - the return of `match`) to construct a v…

Hello, thanks for the great question! Yes, you do have to specify where a variant comes from, but it doesn't have to be nominal at all! Here's an example: ``` enum Option {Some(T), Nothing} // Create a value with an inline type that doesn't use the nominal `Option` let opt1 = enum {Some(Int), Nothing} of Some(5); // Define a second option value, which is assigned with the first let opt2: Option = opt1; // Print the r…

Oh that's cool, and makes sense. Is it possible to perform type widening on enums? Or must they match precisely? For example, what happens if I attempt the below?

``` enum Option {Some(T), Nothing};

let opt1 = enum {Some(Int)} of Some(5);

let opt2: Option = opt1; ```

Post reply on HN