这种So类型的目的是什么?音译到Agda:
data So : Bool ? Set where
oh : So true
Run Code Online (Sandbox Code Playgroud)
So将布尔命题提升为逻辑命题.Oury和Swierstra的介绍性论文"Pi的力量"给出了一个由表格列索引的关系代数的例子.取两个表的产品要求它们具有不同的列,他们使用这些列So:
Schema = List (String × U) -- U is the universe of SQL types
-- false iff the schemas share any column names
disjoint : Schema -> Schema -> Bool
disjoint = ...
data RA : Schema ? Set where
-- ...
Product : ? {s s'} ? {So (disjoint s s')} ? RA s ? RA s' ? RA …Run Code Online (Sandbox Code Playgroud) 让我说我有
prf :: x :~: y
Run Code Online (Sandbox Code Playgroud)
在某些范围内Symbol; 通过模式匹配Refl,我可以将其转换为
prf' :: (x :== y) :~: True
Run Code Online (Sandbox Code Playgroud)
像这样:
fromProp :: (KnownSymbol x, KnownSymbol y) => x :~: y -> (x :== y) :~: True
fromProp Refl = Refl
Run Code Online (Sandbox Code Playgroud)
但另一个方向呢?如果我试试
toProp :: (KnownSymbol x, KnownSymbol y) => (x :== y) :~: True -> x :~: y
toProp Refl = Refl
Run Code Online (Sandbox Code Playgroud)
然后我得到的就是
• Could not deduce: x ~ y
from the context: 'True ~ (x …Run Code Online (Sandbox Code Playgroud) haskell equality dependent-type type-level-computation singleton-type
是否可以编写一个类型级函数,True如果一个类型级别列表包含另一个类型级别列表,则返回该函数?
这是我的尝试:
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module TypePlayground where
import Data.Type.Bool
type family InList (x :: *) (xs :: [*]) where
InList x '[] = 'False
InList x (x ': xs) = 'True
InList x (a ': xs) = InList x xs
type family ListContainsList (xs :: [*]) (ys :: [*]) where
ListContainsList xs (y ': ys) = InList y xs && ListContainsList xs ys
ListContainsList …Run Code Online (Sandbox Code Playgroud) 我使用单一包生成的非常简单的类型级自然.我现在正在尝试向他们添加Ord实例.
{-# LANGUAGE MultiParamTypeClasses, TemplateHaskell, KindSignatures, DataKinds, ScopedTypeVariables, GADTs, TypeFamilies, FlexibleInstances, TypeOperators, UndecidableInstances, InstanceSigs #-}
module Functions where
import Data.Singletons
import Data.Singletons.TH
import Data.Singletons.Prelude
import Data.Promotion.Prelude
singletons [d|
data Nat = Z | S Nat
deriving Eq
instance Ord Nat where
(<=) Z _ = True
(<=) (S _) Z = False
(<=) (S n) (S m) = n <= m
|]
Run Code Online (Sandbox Code Playgroud)
我一直在遇到一个错误.最新的一个是:
src/Functions.hs:10:1:
Couldn't match kind ‘Nat’ with ‘*’
When matching types
n0 :: Nat
t1 :: *
Expected …Run Code Online (Sandbox Code Playgroud)