3 ms·
This basically exists in Haskell/Idris as the Maybe type. It is used slightly differently than what you're saying but in essence it lets you say: - The thing d
by mitchty 8y ago
This basically exists in Haskell/Idris as the Maybe type.
It is used slightly differently than what you're saying but in essence it lets you say:
- The thing doesn't exist, return Nothing (unit in a way)
- The inputs produced Just the thing you wanted
You have to cover both "didn't work" and "here you go" but its highly useful to not have to worry about NULL versus NOT NULL.
https://stackoverflow.com/questions/29456824/what-is-the-maybe-type-and-how-does-it-work https://stackoverflow.com/questions/29456824/what-is-the-may...
Your function that decides if something exists or not, could be the thing determining the percentage spiel.
Aka a function returning Maybe Bool could return: a Bool with true/false, or Nothing. Nothing being "its not a bool, your inputs are insane/nonsensical", but if it returns a Just Bool, you just unbox the Bool and voila. Just thought you might want to know this is a real thing and is super useful.
- sixdimensional 8y agoAh, thank you. I knew it existed in some language, but I couldn't remember where I had seen it. I need to practice Haskell a bit more.. it's not one of the languages I ever seem to get around to.
- mitchty 8y agoIts fun! Also maddening, in the "this is computation in a totally different paradigm" way. But Maybe as an example is one of those things that show you there are better ways than NULL.