I did in ghci:
> :set -XTypeOperators
> import Data.Proxy
> import Data.Type.Equality
> import Data.Singletons.Prelude
> :let p1 = Proxy :: Proxy (Int == Int)
> :let p2 = Proxy :: Proxy (Int :== Int)
> :t p1
p1 :: Proxy 'True
> :t p2
p2 :: Proxy (Int :== Int)
Why in the second case type is not calculated? Can I workaround it somehow? Can I make an instance for class PEq
(where :==
is defined)?
(ghc 7.10.3)
Update: I found how to make an instance. Are there some reasons why it is not included?
> instance PEq ('KProxy :: KProxy *) where { type (:==) x y = x == y }
or simple (as pointed by dfeuer in comments)
> instance PEq ('KProxy :: KProxy *)
or import this instance from TypeRepStar:
> import Data.Singletons.TypeRepStar()
It seems that a reason for not including instance for PEq
for kind *
in singletons
are similar to not including poly-kinded instances for Eq
in base
. It is described here . Such instance too common and if it exists we can't describe eg equalities of type arguments by result of type functions. For example:
Succ n == Succ m = n == m
For workaround in case of singletons
one can define it:
instance PEq ('KProxy :: KProxy *)
Or just use it:
import Data.Singletons.TypeRepStar()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.