Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
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
-
@beegC0de You're right, it's actually a union type in both examples. This is mostly just pseudo syntax
-
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
-
@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.
-
@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
Related Rants
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
rant
type
union
theory
yikes
sum