Earlier quoted context omitted.
It has sum types! Type unions with a discriminator.
It kinda does if https://www.typescriptlang.org/play#example/discriminate-typ... is what you're referring to but it appears to be missing one of the major benefits: an error/warning if you haven't handled all variants. Edit: lots of replies showing how TypeScript can be made to do exhaustiveness checking. It's neat and all but it's a lot of gymnastics compared to languages that just have this built in, which again is…
Building a hybrid native application with Gleam and Tauri
11–20 of 20 posts
Re: Building a hybrid native application with Gleam and Tauri
#12Earlier quoted context omitted.
It has sum types! Type unions with a discriminator.
It kinda does if https://www.typescriptlang.org/play#example/discriminate-typ... is what you're referring to but it appears to be missing one of the major benefits: an error/warning if you haven't handled all variants. Edit: lots of replies showing how TypeScript can be made to do exhaustiveness checking. It's neat and all but it's a lot of gymnastics compared to languages that just have this built in, which again is…
EDIT: and an example of usage: https://github.com/wwtos/mjuo/blob/ca8c514185c1b5bb22aec752a...
Re: Building a hybrid native application with Gleam and Tauri
#13Earlier quoted context omitted.
It has sum types! Type unions with a discriminator.
It kinda does if https://www.typescriptlang.org/play#example/discriminate-typ... is what you're referring to but it appears to be missing one of the major benefits: an error/warning if you haven't handled all variants. Edit: lots of replies showing how TypeScript can be made to do exhaustiveness checking. It's neat and all but it's a lot of gymnastics compared to languages that just have this built in, which again is…
type Variant = { kind: "value", value: string } | { kind: "error", error: string } | { kind: "unexpected" };
class Unreachable extends Error {
constructor(unexpected: never) {
super(`${unexpected}`);
}
}
function useVariant(variant: Variant) {
switch (variant.kind) {
case "value":
return variant.value;
case "error":
return variant.error;
default:
throw new Unreachable(variant);
}
}
The `new Unreachable(variant)` will fail the type check only when you have not exhaustively matched all variants.Re: Building a hybrid native application with Gleam and Tauri
#14Earlier quoted context omitted.
It has sum types! Type unions with a discriminator.
It kinda does if https://www.typescriptlang.org/play#example/discriminate-typ... is what you're referring to but it appears to be missing one of the major benefits: an error/warning if you haven't handled all variants. Edit: lots of replies showing how TypeScript can be made to do exhaustiveness checking. It's neat and all but it's a lot of gymnastics compared to languages that just have this built in, which again is…
type A = { kind: "kindA", a: "dataA" }
type B = { kind: "kindB", b: "dataB" }
type Sum = A | B
const match = unknown }
>( value: V, cases: C ) => cases[ value.kind as V[ "kind" ] ]( value ) as ReturnType
// You check the type of result, change the type of value to A or B, make the cases non-exhaustive...
const howToUse = ( value: Sum ) => {
const result = match( value, {
kindA: _ => _.a,
kindB: _ => _.b
} )
}
You can test it here: https://www.typescriptlang.org/play?#code/C4TwDgpgBAglC8UDeU...Re: Building a hybrid native application with Gleam and Tauri
#15Re: Building a hybrid native application with Gleam and Tauri
#16Recently learned about Gleam and am very interested in it as someone who always wanted to like Elixir but dislikes the Ruby syntax and lack of static typing. Love this approach to demonstrating the language in context. As a mostly frontend dev I feel it’s worth mentioning that while it’s a nice way to try Gleam, the Gleam aspect of this is inessential, TypeScript is quite good, and using create-tauri-app with the rea…
> the Gleam aspect of this is inessential, TypeScript is quite good TypeScript can be quite productive but I find its type system lacking. Specifically the use of structural typing/lack of nominal typing and lack of sum types. I find these extremely useful when writing reliable software, which is why Gleam appeals to me.
Does this prevent you from writing reliable software?
Re: Building a hybrid native application with Gleam and Tauri
#17Recently learned about Gleam and am very interested in it as someone who always wanted to like Elixir but dislikes the Ruby syntax and lack of static typing. Love this approach to demonstrating the language in context. As a mostly frontend dev I feel it’s worth mentioning that while it’s a nice way to try Gleam, the Gleam aspect of this is inessential, TypeScript is quite good, and using create-tauri-app with the rea…
Typescript's type system isn't sound. Gleam's is.
Re: Building a hybrid native application with Gleam and Tauri
#18Re: Building a hybrid native application with Gleam and Tauri
#19Re: Building a hybrid native application with Gleam and Tauri
#20FYI Celcius -> Celsius https://en.wikipedia.org/wiki/Celsius
Edit: fixed now (might take a few mins for the cache to expire).