flat-maybe
flat-maybe copied to clipboard
A possible solution to the nested Maybes issue
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.