flat-maybe icon indicating copy to clipboard operation
flat-maybe copied to clipboard

A possible solution to the nested Maybes issue

Open nikita-volkov opened this issue 8 years ago • 0 comments

Have you considered having multiple definitions of null, one per the level of nesting? E.g.,

data Null1 = Null1
data Null2 = Null2
-- ...

-- Equivalent of `Nothing :: Maybe (Maybe Int)`
twoLevelMaybeNothing :: Maybe (Maybe Int)
twoLevelMaybeNothing = unsafeCoerce Null2

-- Equivalent of `Just Nothing :: Maybe (Maybe Int)`
twoLevelMaybeJustNothing :: Maybe (Maybe Int)
twoLevelMaybeJustNothing = unsafeCoerce Null1

Then the choice of the proper null could be determined through type-classes or reflection.

nikita-volkov avatar Jun 17 '17 15:06 nikita-volkov