Is there a way to apply a function passed as an argument to two different types? As a far-fetched example, I can create (Maybe Int, Maybe Bool)with an expression (Just 3, Just True), but if I try to make this behavior more general using a function
generic :: (a -> Maybe a) -> (Maybe Int, Maybe Bool)
generic f = (f 3, f True)
so that I can do something like generic Just, the compiler complains because the type variable ais constant.
In this case, the general function is applied to the tree structure, where each node is parameterized by a type.
source
share