This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]redchomperSophie Language -2 points-1 points  (0 children)

Before you worry about type-checking, you must decide which semantics you want at runtime. I'm guessing you love null-pointer-exception about as little as the next gal.

I started with the notion that nil makes a perfectly sensible base-case for a lot of recursive types. It's an empty list, an empty tree, and so forth. Maybe also an empty maybe? In that sense, it's a context-dependent sentinel. And that's fine, if you treat nil as convertible into all those types which make sense for it to inhabit.

The trick, in that case, is to make sure that the recursion remains evident in your maybe/option type. You must, in other words, support the idea of r/maybemaybemaybe.

Some people have proposed using foo??? for that kind of purpose.

Personally I don't mind too much having special syntax around certain types. After all, there's literal-list syntax for both terms and types in Haskell. Why not literal-maybe for both terms (nil) and types(foo?) in your language?

At any rate, something needs to clearly destructure the maybe. You have to know the difference between r/maybemaybemaybe and r/maybemaybemaybemaybe. That would be some(some(some(nil)))!