Skip to content

Instantly share code, notes, and snippets.

@stijnherreman
Created Dec 28, 2016
Embed
What would you like to do?

While creating a client for a web API in C#, I ran into a problem regarding null as a value where it would represent two different things:

  • nothing, e.g. a foo may or may not have a bar
  • unknown: by default the API response only includes a subset of properties, you have to indicate which additional properties you want. So unknown means that the property was not requested from the API.

After some searching I found out about the Maybe (or Option) type, how it's used in functional languages and how it "solves" null dereferencing problems by forcing the user to think about the possible absence of a value. However, all of the resources I encountered talked about replacing null with Maybe. I did find some mentions of three-valued logic, but I don't fully understand it and most of the times its mentioning was in the context of "it's a bad thing".

I'm now wondering if it makes sense to have both the concept of null and Maybe, to represent unknown and nothing respectively. Is this the three-valued logic I read about, or does it have another name? Or is the intended way to nest a Maybe in a Maybe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment