Is there any way to apply a function passed as an argument to two different types? As a contrived example, I can create a (Maybe Int, Maybe Bool)
with the expression (Just 3, Just True)
, but if I try to make this behaviour more generic with the function
generic :: (a -> Maybe a) -> (Maybe Int, Maybe Bool)
generic f = (f 3, f True)
so that I might be able to do something like generic Just
, the compiler complains because the type variable a
is constant.
The use case of this is applying a generic function to a tree structure where each node is parametrized by a type.