Consider the following method count, which maps the natural numbers of a level to level values:
{-# LANGUAGE
DataKinds
, KindSignatures
, PolyKinds
, FlexibleInstances
, FlexibleContexts
, ScopedTypeVariables
module Nat where
data Nat = Z | S Nat
data Proxy (a :: k) = Proxy
class Count a where
count :: a -> Int
instance Count (Proxy Z) where
count _ = 0
instance Count (Proxy n) => Count (Proxy (S n)) where
count _ = succ $ count (Proxy :: Proxy n)
It seems to work in repl:
λ count (Proxy :: Proxy (S(S(S Z))) )
3
There Proxymust be some indication to complete the recursion at runtime of the type , but it is assumed that the types will be erased at runtime. I can even replace datawith newtypein the definition Proxy:
newtype Proxy (a :: k) = Proxy ()
- Which would oblige him to have the same representation of memory every time, so that was it Coercible. With that in mind:
I do not completely understand how the method is dispatched. I would suggest that:
- (, ) ⟶ . , , . , , .
- ⟶ , . - , . , , , .
- ( , ) ⟶ , ( → ) . , , , , . , - .
, , , - , . - , , :
... Et cetera.
, , 2 count, 1 . (, Proxy , " A 1 ", 1 Proxy " A 0 ".) . -, , .
, ?