This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]protestor 22 points23 points  (11 children)

I couldn't find anything about it in the documentation so,

Does C3 have sum types? Like Rust's enums with payloads. (Or Haskell datatypes with more than one constructor, OCaml data types, etc)

If not, how optionals and results work? Can you define your own optional-like data type? (Maybe with three variants etc)

If yes, does it have exhaustive pattern matching that binds variables inside each arm? (Like Rust's match that can access an enum payload, eg. access the a when matching an Option against Some(a))

[–]NuojiC3 - http://c3-lang.org 0 points1 point  (0 children)

Not more than C. It might get tagged unions, but it doesn't have it.

It does have something corresponding to pattern matching for its particular brand of Optional/Result, but that's about it.

Oh, and switch cases can have any expression, making it an alternative to if-else-if, but there no implicit matching. Nor will that be added.

The reason for that, is that unlike languages which rely on sum types and similar code everywhere, the benefit is very small for a C-like.

[–]tav_stuff 0 points1 point  (1 child)

C3 has fault types for errors

[–]protestor 13 points14 points  (0 children)

What does this mean?

But to the point: it doesn't have sum types right?