Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Some questions about optionals #321

Closed
kach opened this issue Jul 21, 2018 · 6 comments
Closed

Some questions about optionals #321

kach opened this issue Jul 21, 2018 · 6 comments
Assignees
Labels
Type: Question ❓ Further information is requested

Comments

@kach
Copy link
Contributor

kach commented Jul 21, 2018

In EData.v, what's the difference between dleft and dright vs dsuccess and derror vs dsome and dnone vs dunit? It seems that return some(10); in the REPL gives a dleft, not a dsome? At least, when it prints JSON, it's {"left": 10}. Similarly, an enforce error gives a dright.

(Also, how do you create a none in the REPL? return none(); doesn't work, not sure what else to try.)

P.S. The fact that I'm confused about this means that the REPL's match almost certainly does the wrong thing for optionals. So while this issue is a question, I guess it is actually also a bug report in disguise.

@kach kach added the Type: Question ❓ Further information is requested label Jul 21, 2018
@jeromesimeon
Copy link
Member

dleft and dright are constructor for a sum type with left and right components.

Those are used internally by the compiler in two ways:

  • support for errors (e.g., a call to a statement returns either a success or an error). This is encoded using the dsuccess and derror macros over dleft and dright.
  • support for optionals (e.g., an optional is either some value or none). This is encoded using the dsome and dnone macros over dleft and dright.

For a reason I cannot recall the syntax for none is nil. This probably should be changed to none for consistency.

@kach
Copy link
Contributor Author

kach commented Jul 23, 2018

Okay, so it seems that dnone is equal to dright dunit. Makes more sense now. I can go fix match.

nil should definitely be renamed to none.

@kach
Copy link
Contributor Author

kach commented Jul 23, 2018

Wait, no, we need separate names for dunit and dright dunit. none should be the latter, and maybe null should be dunit.

@jeromesimeon
Copy link
Member

I like the idea of having either none be dright dunit, but I think using null for dunit is very confusing since it's completely different from the use of null in other languages. How about unit! -- I'm not even sure we need a syntax for that since you can't have a CTO type.

@kach
Copy link
Contributor Author

kach commented Aug 3, 2018

none => none, i.e. dright dunit now, but nil is still dunit (#366)

@kach kach mentioned this issue Aug 10, 2018
@jeromesimeon
Copy link
Member

This looks fixed:

Screen Shot 2019-03-14 at 3 45 07 PM

I'm closing this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Question ❓ Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants