- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试使用 DataKinds
在 Haskell 中实现类型级自然。延期。到目前为止,我的代码如下所示:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GADTs #-}
-- the kind of natural numbers
data Nat = Zero | Succ Nat
-- type synonyms for the naturals
type N0 = Zero
type N1 = Succ N0
type N2 = Succ N1
-- ...
-- singleton natural type
data SNat (n :: Nat) where
SZero :: SNat Zero
SSucc :: SNat n -> SNat (Succ n)
-- type level lesser-than operator
type family (<) (x :: Nat) (y :: Nat) :: Bool where
x < Zero = False
Zero < y = True
(Succ x) < (Succ y) = x < y
-- type level addition operator
type family (+) (x :: Nat) (y :: Nat) :: Nat where
Zero + y = y
x + Zero = x
(Succ x) + y = Succ (x + y)
x + (Succ y) = Succ (x + y)
infixr 5 :::
-- type of vectors with a certain length
data Vector (n :: Nat) a where
Nil :: Vector N0 a
(:::) :: a -> Vector n a -> Vector (Succ n) a
-- indexing operator
(!) :: ((k < n) ~ True) => Vector n a -> SNat k -> a
(x ::: _) ! SZero = x
(_ ::: xs) ! (SSucc n) = xs ! n
> (1 ::: 2 ::: 3 ::: Nil) ! (SSucc SZero)
2
> (1 ::: Nil) ! (SSucc SZero)
Couldn't match type 'False with 'True....
(:::) :: a -> Vector n a -> Vector (Succ n) a
(:::) :: a -> Vector n a -> Vector (n + N1) a
Could not deduce ((n2 < n1) ~ 'True)
from the context ((k < n) ~ 'True)
bound by the type signature for
(!) :: (k < n) ~ 'True => Vector n a -> SNat k -> a
at question.hs:41:8-52
or from (n ~ (n1 + N1))
bound by a pattern with constructor
::: :: forall a (n :: Nat). a -> Vector n a -> Vector (n + N1) a,
in an equation for ‘!’
at question.hs:43:2-9
or from (k ~ 'Succ n2)
bound by a pattern with constructor
SSucc :: forall (n :: Nat). SNat n -> SNat ('Succ n),
in an equation for ‘!’
at question.hs:43:15-21
Relevant bindings include
n :: SNat n2 (bound at question.hs:43:21)
xs :: Vector n1 a (bound at question.hs:43:8)
In the expression: xs ! n
In an equation for ‘!’: (_ ::: xs) ! (SSucc n) = xs ! n
n < Succ n
但不是那个
n < n + N1
?在这种情况下,如何使我的类型函数正常运行? (我宁愿不必使用
unsafeCoerce
)。
最佳答案
您可以通过减少 (+)
的定义来使用更改后的类型签名进行编译。类型家庭:
-- type level addition operator
type family (+) (x :: Nat) (y :: Nat) :: Nat where
-- Zero + y = y
x + Zero = x
-- (Succ x) + y = Succ (x + y)
x + (Succ y) = Succ (x + y)
(n + N1)
不能减少,因为 GHC 不知道它可以应用哪些方程;第一个可能适用,取决于是否
n
是
Zero
.
N1
减少到其定义之后)只有
x + Succ y
规则可以适用,因此 GHC 能够将您的新类型减少到原始类型。
(+)
这样的操作其实更正常通过对第一个参数的案例分析,而不是我在这里所做的第二个。那会让事情像
(N1 + n)
工作但不工作
(n + N1)
.但是,我认为这只是一种约定,而不具有任何特定优势。
关于haskell - 按类型级别自然排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26048886/
Android 项目中最低(最低 sdk)和最高(目标 sdk)级别是否有任何影响。这些东西是否会影响项目的可靠性和效率。 最佳答案 没有影响,如果您以 SDK 级别 8 为目标,那么您的应用将以 9
我将现有的 android 项目升级到 API 级别 31。我使用 Java 作为语言。我改变了 build.gradle compileSdkVersion 31 defaultConfig {
我正在使用 ionic 3 创建一个 android 应用程序,当我尝试上传到 playstore 时,我收到一个错误,提示我的应用程序以 api 25 为目标,当我检查我的 project.prop
我刚刚尝试将应用程序的目标和编译 API 级别更新为 29 (Android 10),并注意到我无法再编译,因为 LocationManager.addNmeaListener 只接受 OnNmeaM
我的代码没有在 Kitkat 上显示工具栏。 这是我的两个 Android 版本的屏幕截图。 Kitkat 版本: Lollipop 版: 这背后的原因可能是什么。 list 文件
我正在构建面向 API 级别 8 的 AccessabilityService,但我想使用 API 级别 18 中引入的功能 (getViewIdResourceName())。这应该可以通过使用 A
当我想在我的电脑上创建一个 android 虚拟机时,有两个选项可以选择目标设备。它们都用于相同的 API 级别。那么我应该选择哪一个呢?它们之间有什么区别? 最佳答案 一个是基本的 Android,
当我选择 tagret 作为 Android 4.2.2(API 级别 17)时,模拟器需要很长时间来加载和启动。 所以我研究它并通过使用 找到了解决方案Intel Atom(x86) 而不是 ARM
我有一个使用 Android Studio 创建的 Android 项目。我在项目中添加了一些第三方依赖项,但是当我尝试在 Android Studio 中编译时,我遇到了以下错误: Error:Ex
如上所述,如何使用 API 8 获取移动设备网络接口(interface)地址? 最佳答案 NetworkInterface.getInetAddresses() 在 API8 中可用。 关于andr
我想显示 Snackbar并使用图像而不是文本进行操作。 我使用以下代码: val imageSpan = ImageSpan(this, R.drawable.star) val b
我有一个用 python 编写的简单命令行程序。程序使用按以下方式配置的日志记录模块将日志记录到屏幕: logging.basicConfig(level=logging.INFO, format='
使用下面的代码,实现游戏状态以控制关卡的最简单和最简单的方法是什么?如果我想从标题画面开始,然后加载一个关卡,并在完成后进入下一个关卡?如果有人能解释处理这个问题的最简单方法,那就太好了! impor
我想创建一个可以找到嵌套树结构深度的属性。下面的静态通过递归找出深度/级别。但是是否可以将此函数作为同一个类中的属性而不是静态方法? public static int GetDepth(MenuGr
var myArray = [{ title: "Title 1", children: [{ title: "Title 1.1", children: [{
通过下面的代码,实现游戏状态来控制关卡的最简单、最容易的方法是什么?如果我想从标题屏幕开始,然后加载一个关卡,并在完成后进入下一个关卡?如果有人可以解释处理这个问题的最简单方法,那就太好了! impo
我有一个树结构,其中每个节点基本上可以有无限个子节点,它正在为博客的评论建模。 根据特定评论的 ID,我试图找出该评论在树中的深度/级别。 我正在关注 this guide that explains
考虑任何给定的唯一整数的数组,例如[1,3,2,4,6,5] 如何确定“排序度”的级别,范围从 0.0 到 1.0 ? 最佳答案 一种方法是评估必须移动以使其排序的项目数量,然后将其除以项目总数。 作
我如何定义一个模板类,它提供一个整数常量,表示作为输入模板参数提供的(指针)类型的“深度”?例如,如果类名为 Depth,则以下内容为真: Depth::value == 3 Depth::value
我的场景是:文件接收器应该包含所有内容。另一个接收器应包含信息消息,但需要注意的是 Microsoft.* 消息很烦人,因此这些消息应仅限于警告。两个sink怎么单独配置?我尝试的第一件事是: str
我是一名优秀的程序员,十分优秀!