One way is to use asTypeOf
:: a -> a -> a
. As a function, asTypeOf
isn't very interesting, but its type is nice: it forces its two arguments and its return type to unify. So:
> :t asTypeOf (undefined :: Int -> Bool) (undefined :: a -> Bool)
asTypeOf (undefined :: Int -> Bool) (undefined :: a -> Bool)
:: Int -> Bool
So you can see that those two types unified to Int -> Bool
. For a slightly more interesting example, let's unify Maybe a
and f (Bool, c)
:
> :t asTypeOf (undefined :: Maybe a) (undefined :: f (Bool, c))
asTypeOf (undefined :: Maybe a) (undefined :: f (Bool, c))
:: Maybe (Bool, c)
On the other hand, for the purpose of exercises, I encourage you to attempt to do the unification by hand. It's not hard, once you get the hang of it, and is a skill that you will use over and over.