Live data from Hacker News

Type-checked non-empty strings

exploring-better-ways.bellroy.com

11–20 of 51 posts

Re: Type-checked non-empty strings

#11

Language is not mentioned in a title, so my first thought was about TypeScript type wizardry. Turns out it's as simple as `Exclude `. https://www.typescriptlang.org/docs/handbook/utility-types.h... Edit: nevermind, LLM fooled me.

Daily reminder that TypeScript's type checker is not sound.

https://www.typescriptlang.org/play/?#code/C4TwDgpgBAcg9gOwK...

Re: Type-checked non-empty strings

#12
post #5

"Huh never heard of Bellroy... I wonder what they're using Haskell for..." Turns out it's some kind of bags and accessories brand!

I've had a Bellroy bag, they're not the most fashionable but super high quality and well thought-out. Just like Haskell code—maybe that's why they like it.

Re: Type-checked non-empty strings

#14

Language is not mentioned in a title, so my first thought was about TypeScript type wizardry. Turns out it's as simple as `Exclude `. https://www.typescriptlang.org/docs/handbook/utility-types.h... Edit: nevermind, LLM fooled me.

Daily reminder that TypeScript's type checker is not sound. https://www.typescriptlang.org/play/?#code/C4TwDgpgBAcg9gOwK...

This example is not only wrong for what you intend to demonstrate but even if it wasn't, it's not problematic. In typescript the proper way to do this is using branded types and exporting only the safe constructor, making anyone who wants to violate the invariant go out of their way, which is no different from the situation in any number of programming languages or scenarios.

  declare const brand: unique symbol;
  type NonEmptyString = string & { readonly [brand]: 'NonEmptyString' };

  // the ONLY non-cast way to produce one
  export function nonEmptyString(s: string): NonEmptyString | undefined {
    return s.length > 0 ? (s as NonEmptyString) : undefined;
  }

  export type { NonEmptyString };

Re: Type-checked non-empty strings

#15
post #5

"Huh never heard of Bellroy... I wonder what they're using Haskell for..." Turns out it's some kind of bags and accessories brand!

I once saw a job ad for a company selling a horoscope app that required Haskell. An unusual conjunction for sure.

Using Haskell for a horoscope app is like hiring a mathematician to read tea leaves

Re: Type-checked non-empty strings

#16
post #5

"Huh never heard of Bellroy... I wonder what they're using Haskell for..." Turns out it's some kind of bags and accessories brand!

I once saw a job ad for a company selling a horoscope app that required Haskell. An unusual conjunction for sure.

Astrology and Haskell are quite similar in that both are much much easier to do if you have a math degree.

Re: Type-checked non-empty strings

#17
post #5

"Huh never heard of Bellroy... I wonder what they're using Haskell for..." Turns out it's some kind of bags and accessories brand!

I've had a Bellroy bag, they're not the most fashionable but super high quality and well thought-out. Just like Haskell code—maybe that's why they like it.

In the backpack community bellroy is often seen as “meh”. Eg. they frequently don’t live up to the guarantees they give and to the quality they promise. Also overpriced.

Re: Type-checked non-empty strings

#18
post #15

Earlier quoted context omitted.

I once saw a job ad for a company selling a horoscope app that required Haskell. An unusual conjunction for sure.

Using Haskell for a horoscope app is like hiring a mathematician to read tea leaves

Astrology is a mixture of factual verifiable information (such as apparent positions of celestial bodies at the time and location a certain person was born) and random baseless divinations.

The "whale" users who account for a disproportionately large percentage of an astrologer's revenue tend to know the factual information surrounding their birth fairly well. An app/astrologer who doesn't get these facts right, even for a handful of clients, will get a bad reputation fairly quickly.

I reckon the same principle would hold in cultural bubbles where reading tea leaves is a customary means of divination. If the client recognizes recognize black tea, but the fortuneteller insists it is rooibos, there won't be much trust in the rest of the prophecy.

Advertising that the horoscope shop uses Haskell is actually a solid business idea. It pre-filters for the sort of dev who will be able to do the math.

Re: Type-checked non-empty strings

#19

Earlier quoted context omitted.

I once saw a job ad for a company selling a horoscope app that required Haskell. An unusual conjunction for sure.

Astrology and Haskell are quite similar in that both are much much easier to do if you have a math degree.

Ok, I'll bite. How does a math degree help with astrology?

Re: Type-checked non-empty strings

#20

Language is not mentioned in a title, so my first thought was about TypeScript type wizardry. Turns out it's as simple as `Exclude `. https://www.typescriptlang.org/docs/handbook/utility-types.h... Edit: nevermind, LLM fooled me.

Daily reminder that TypeScript's type checker is not sound. https://www.typescriptlang.org/play/?#code/C4TwDgpgBAcg9gOwK...

It is true, but it wasn't meant to be sound, so it's okay.

You can do this trick for type-checking emptiness of string literals

https://www.typescriptlang.org/play/?jsx=0#code/C4TwDgpgBAsg...

Post reply on HN