6

I don't know what to do because union and sum types both totally suck but I need them for my scripting language

Union types are fun and intuitive because they can be used with type refinement but they're not hierarchical thus bad for generics.

Sum types (or tagged unions) are great because they're hierarchical and can be nested properly but they need ugly type matching constructs.

The positive thing is I'm not making a systems language anymore so I only wanna jump of a bridge every second day

Comments
  • 2
    Why do you need to declare the second function to return Some<T> or null? Shouldn't it return a single type that can either be Some<T> or Null/None? Doesn't seem all that different from the first function to me
  • 2
    @beegC0de You're right, it's actually a union type in both examples. This is mostly just pseudo syntax
  • 2
    The idea was to have a weird union/sum type hybrid (aka a partially tagged union) consisting of an untagged part (like null in the example) and tagged parts. I don't know doesn't really work that well in practice
  • 1
    @12bitfloat I like that tagged unions have to be matched/deconstructed so you can't really use them in an unsafe way unless explicitly doing it.
  • 1
    @beegC0de True, but my lang is strongly typed anyway so with an untagged union type "String|null" you could only access common members (defined via heritance). My problem with match constructs is that they are most of the time rather ugly and unwieldly. Especially if they're implement via a pseudo switch statement because then the code for every alternative has two indentations
Add Comment