Just move on to the last one, that the other answers are not covered ...
*Euler> :t prime prime :: (Integral a, RealFrac a, Floating a) => a -> Bool
The typechecker method states that prime can accept an argument of type a , while a is an instance of the Integral , RealFrac and Floating classes at once.
*Euler> prime 5 <interactive>:1:0: Ambiguous type variable `t' in the constraints: `Floating t' arising from a use of `prime' at <interactive>:1:0-6 `RealFrac t' arising from a use of `prime' at <interactive>:1:0-6 `Integral t' arising from a use of `prime' at <interactive>:1:0-6 Probable fix: add a type signature that fixes these type variable(s)
When you request its prime 5 , however, it complains that none of the 5 types by default can satisfy these conditions.
It is possible that you could write your own
instance (Integral a, RealFrac b, Floating b) => Integral (Either ab) where ... instance (Integral a, RealFrac b, Floating b) => RealFrac (Either ab) where ... instance (Integral a, RealFrac b, Floating b) => Floating (Either ab) where ...
(and you will also need to add Num , Ord , Real , Fractional , etc. instances), and then prime 5 will be acceptable, since there is 5 :: Either Integer Float that satisfies type conditions.
source share