One way is to use . As a function, it’s not very interesting, but its type is good: it combines two of its arguments and its return type. So:asTypeOf :: a -> a -> aasTypeOf
> :t asTypeOf (undefined :: Int -> Bool) (undefined :: a -> Bool)
asTypeOf (undefined :: Int -> Bool) (undefined :: a -> Bool)
:: Int -> Bool
So you can see that these two types are unified before Int -> Bool. For a slightly more interesting example, let me unify Maybe aand 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 exercises, I urge you to try to do the merging manually. It is not difficult as soon as you get it, and it is a skill that you will use again and again.
source
share