|
|
|
|
|
by david-given
3896 days ago
|
|
Yeah, but you're comparing apples and oranges. The nullable case isn't preserving the information you want, because you haven't written the code to preserve it, while in your Maybe case, you have. The two examples you give aren't doing the same thing. Your nullable example is better compared to this, which also discards the required information: spouseDOB :: User -> Maybe DateOfBirth
spouseDOB u = case getSpouse u in
s -> getDOB s
Nothing -> Nothing
Likewise, the nullable case, modified to preserve it (in a language which actually has nulls this time): DateOfBirth* spouseDOB(User& user) {
Spouse* spouse = getSpouse(user);
if (spouse)
return &spouse->dateOfBirth;
return NULL;
}
Maybes are just pointers. There's nothing magic about them. |
|
Exactly. Your version is just doing what `join` or `>>=` would do, which I mentioned at the end; ie.
> Maybes are just pointers. There's nothing magic about them.Of course there's nothing magic; `Maybe` just increments types. I was phrasing myself in the context of a language like Java, which has NULL but no pointer manipulation.