Kirill Bubochkin
1 min readMar 12, 2022

Yes, but null is a value as well.

Wrapping into Option doesn't make any difference, in fact, T? is already Dart equivalent of Option<T> that means T | null.

Speaking about totality, don't confuse Unit type and Bottom type. There is a common error, when people say "function returns nothing" meaning that function returns null. Correct way to say is that function returns value of Unit, while returning nothing means that it returns Bottom type (which represents "nothing").

Unit type in Dart can be represented by Null type which has the only value – null. Bottom type in Dart is represented by Never type. Thus, partial function can be specified like that (in pseudo code since Dart doesn't support this syntax):

String | Never f(int a) {

if (a == 0) return "0";

throw ArgumentError();

}

In Dart, as in the majority of programming language, function returns Never if it throws an exception or has an infinite loop.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Kirill Bubochkin
Kirill Bubochkin

Responses (1)

Write a response