I am trying to write a function whose third parameter can be an (Int, Int) or a Maybe (Int, Int). Is this possible?
randomFunction :: [Char] -> [[Int]] -> Either (Int, Int) Maybe (Int, Int) -> Bool
CodePudding user response:
The syntax for the thing you ask is:
Either (Int, Int) (Maybe (Int, Int))
But this is unlikely to be the idiomatic solution. I suspect it's much more likely to be one of these two solutions:
- Accept only
Maybe (Int, Int). Callers that have an(Int, Int)in hand can wrap it in aJust. (This solution can always be applied.) - Accept only
(Int, Int). Offer a default(Int, Int)-- say,(0, 0), though of course the right choice depends on what the function does -- that callers can use if they have aMaybe (Int, Int)and its value isNothing. (This solution is almost always possible, but in rare cases, the function might treatNothingso specially that it cannot be emulated by any specific(Int, Int).)
