, .
:
class C a where def :: (Int, a)
f :: (Eq a, C a) => Int -> (a, Bool)
f x = let (y,z) = def in (z, x==y)
: a ( C) a Bool. , , a. , , :
> instance C Char where def = (0, 'a')
> instance C () where def = (1, () )
> f 0 :: (Char,Bool)
('a', True)
> f 0 :: ((), Bool)
((), False)
:
> snd (f 0) :: Bool
: True, False , a f. , a, .
:
f :: (Eq a, C a) => Int -> (a, Bool) -- OK
f 0 :: (Eq a, C a) => (a, Bool) -- OK
snd (f 0) :: (Eq a, C a) => Bool -- NOT OK
, a , , .
, a , .
snd (f 0 :: (Char, Bool)) :: Bool -- OK
mulGF2n :: (Bits a, Bits t1, Bits t) => a -> t -> t -> (t1, t)
,
g :: (Bits a, Bits t1, Bits t) => a -> t -> t -> t
g a b c = snd $ mulGF2n a b c
t1 , . t1=t, :
g :: (Bits a, Bits t) => a -> t -> t -> t
g a b c = y `asTypeOf` x
where (x,y) = mulGF2n a b c
asTypeOf Haskell , y x .
asTypeOf :: a -> a -> a
asTypeOf x y = x
, a -> b -> a, . , , .
( - ScopedTypeVariables, .)