top | item 31152014

(no title)

aledue | 3 years ago

Are hare's tagged unions and pattern matching comparable to ADTs found in functional languages? I really miss them in C and would like a "better C" that offers them. Rust does, but of course it's a much bigger language.

discuss

order

turminal|3 years ago

Hare doesn't care much about mathematical purity, and the features it does have were chosen on the basis of what is useful in systems programming.

There are sum types (tagged unions), but product types (tuples) were a late addition and we still don't have support for tuple unpacking or pattern matching on them.

Tuple unpacking is something that's been put off for very long but looks like it is going to finally happen soon. Pattern matching on types other than tagged unions hasn't been completely ruled out yet, but is also not guaranteed to happen.

ddevault|3 years ago

They are a subset, I suppose. I'm not an expert at functional programming so I couldn't say. The tutorial which introduces tagged unions is here:

https://harelang.org/tutorials/introduction/#tagged-unions-i...

They are also covered in section 6.5.18 of the Hare specification:

https://harelang.org/specification.pdf

Would be curious to hear your thoughts on how they compare given your (presumed) background in functional programming.

erk__|3 years ago

The biggest missing feature here would be a way to not only select by type and for example allow something like

   type foo = (A int | B int)
Which from my cursory reading does not seem to be possible?

aledue|3 years ago

Thank you, from the other replies it seems like they would be enough for my needs.

> Would be curious to hear your thoughts on how they compare given your (presumed) background in functional programming.

I'm just a student with an interest in programming languages and very little knowledge and experience, so I don't think I'll be able to provide any significant insight ;)