1{-# LANGUAGE FlexibleContexts, TypeSynonymInstances, 2 FlexibleInstances, TypeFamilies, 3 UndecidableSuperClasses #-} 4 5module T10318 where 6 7-- | Product of non-zero elements always non-zero. 8-- Every integral domain has a field of fractions. 9-- The field of fractions of any field is itself. 10class (Frac (Frac a) ~ Frac a, Fractional (Frac a), IntegralDomain (Frac a)) 11 => IntegralDomain a where 12 type Frac a :: * 13 embed :: a -> Frac a 14 15instance IntegralDomain Integer where 16 type Frac Integer = Rational 17 embed = fromInteger 18 19instance IntegralDomain Rational where 20 type Frac Rational = Rational 21 embed = id 22 23g :: IntegralDomain a => a -> a 24g x = g x 25 26h :: a -> Frac a 27h x = h x 28 29-- This is the test function 30 31f :: IntegralDomain a => a -> Frac a 32f x = g (h (h x)) 33 -- Given: IntegralDomain (Frac a) 34 -- Wanted: IntegralDomain (Frac (Frac a)) 35 36