-, call : c x Proxy c -> (forall a . c a => a -> Int) -> x -> Int, x f.
, unsafeCoerce . unsafeCoerce, :
withCall
:: (forall d . (Foo (D d), Bar d) => D d -> Bool)
-> (forall a . FConstraint a => a -> Int)
withCall = unsafeCoerce
D d Bool Int. ( , ImpictictiveTypes). , , , unsafeCoerce, , , , .
FConstraint :
class UnD x (y :: Nat) | x -> y
instance UnD (D x) x
class FConstraint x
instance (Foo x, Bar t, UnD x t) => FConstraint x
:
{-# LANGUAGE
UndecidableInstances
, ImpredicativeTypes
, MultiParamTypeClasses
, FunctionalDependencies
import Unsafe.Coerce
import GHC.Exts (Constraint)
import Data.Proxy
import GHC.TypeLits
class Foo f
class Bar (b :: Nat)
data D (d :: Nat) = D
call :: Proxy (c :: * -> Constraint) -> (forall a . c a => a -> Int) -> x -> Int
call = undefined
f :: (Foo (D d), Bar d) => D d -> Bool
f = error ""
withCall :: (forall d . (Foo (D d), Bar d) => D d -> Bool) -> (forall a . FConstraint a => a -> Int)
withCall = unsafeCoerce
class UnD x (y :: Nat) | x -> y
instance UnD (D x) x
class FConstraint x
instance (Foo x, Bar t, UnD x t) => FConstraint x
main = print $ call (Proxy :: Proxy FConstraint) (withCall f) (D :: D 17)
, , TypesToProps:
class TypesToProps xs (c :: k -> Constraint) (t :: k -> *) where
tmap :: Proxy xs -> Proxy c -> Proxy t -> (forall a . c a => t a -> Bool) -> [Property]
instance TypesToProps '[] c t where
tmap _ _ _ _ = []
instance (c x, TypesToProps xs c t, Arbitrary (t x), Show (t x)) => TypesToProps (x ': xs) c t where
tmap _ c t f = property (f :: t x -> Bool) : tmap (Proxy :: Proxy xs) c t f
main = defaultMain $ map (testProperty "zq_f_id") $
tmap (Proxy :: Proxy '[3, 5, 7, 11])
(Proxy :: Proxy KnownNat)
(Proxy :: Proxy Zq)
prop_f
, unsafeCoerce.
unsafeCoerce prop_f, , KnownNat q , - . , , , .
( ):
data Dict p where
Dict :: p => Dict p
, :
anyDict :: Dict p
anyDict = unsafeCoerce (Dict :: Dict (Eq ()))
prop_f' :: forall q . Zq q -> Bool
prop_f' q = case anyDict :: Dict (KnownNat q) of Dict -> prop_f q
, , q in Zq q phantom -, Zq, q , .
class TypesToProps xs where
tmap :: Proxy xs -> (forall a . a -> Bool) -> [Property]
instance TypesToProps '[] where
tmap _ _ = []
instance (TypesToProps xs, Arbitrary x, Show x) => TypesToProps (x ': xs) where
tmap _ f = property (f :: x -> Bool) : tmap (Proxy :: Proxy xs) f where
, forall a . a -> Bool , unsafe. , , tmap; , tmap. :
main = defaultMain $ map (testProperty "zq_f_id") $
tmap (Proxy :: Proxy '[Zq 3, Zq 5, Zq 7, Zq 11])
(unsafeCoerce prop_f' :: forall a . a -> Bool)