- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的代码:
{-# LANGUAGE TypeFamilies, TypeOperators, DataKinds, PolyKinds, FlexibleContexts, UndecidableInstances #-}
module Foo where
import Data.Singletons.Prelude
import Data.Type.Equality
data TP a b
-- foldl (\(bool, r) x -> (bool && (r == x), r)) (True, head xs) xs
type family Same (b :: Bool) (r :: k) (rq :: [k]) :: k where
Same bool r (x ': xs) = Same (bool :&& (r == x)) r xs
Same bool r '[] = TP bool r
data NotEqualFailure
-- converts a True result to a type
type family EqResult tp where
EqResult (TP 'True r) = r
EqResult (TP 'False r) = NotEqualFailure
data Zq q i
type family Foo rq
type instance Foo (Zq q i) = i
type R =
EqResult
(Same 'True (Foo (Zq Double Int))
(Map (TyCon1 Foo)
'[Zq Double Int, Zq Float Int]))
f :: R
f = 3
No instance for (Num NotEqualFailure)
arising from a use of ‘f’
In the expression: f
In an equation for ‘it’: it = f
f
并启动 GHCi:
> :kind! R
R :: *
= Int
EqResult
应该返回公共(public)类型(这里是
Int
),否则返回
NotEqualFailure
.谁能解释这里发生了什么?如果您也认为这看起来像一个错误,请告诉我,我会将其归档在 GHC trac 上。
{-# LANGUAGE TypeFamilies, TypeOperators, DataKinds, FlexibleContexts, UndecidableInstances #-}
module Foo where
import Data.Singletons.Prelude
import Data.Singletons.Prelude.List
import Data.Type.Equality
-- foldl (\(bool, r) x -> (bool && (r == x), r)) (True, head xs) xs
type family Same rq where
Same (x ': xs) =
EqResult (And (Map ((TyCon2 (==)) $ x) xs)) x
data NotEqualFailure
-- converts a True result to a type
type family EqResult b v where
EqResult 'True r = r
EqResult 'False r = NotEqualFailure
type R = Same '[Int, Int]
f :: R
f = 3
R
至
Int
,但 GHC 无法解析
EqResult
的类型族现在完全没有(在它错误地将其解析为
NotEqualFailure
之前)。请注意,如果我将列表的大小更改为 1,即
'[Int]
,则此示例有效。 .
{-# LANGUAGE TypeFamilies, DataKinds,
UndecidableInstances #-}
module Foo where
type family Same (rq :: [*]) :: * where
Same (x ': xs) = EqTo x xs
--tests if x==y for all x\in xs
type family EqTo y xs where
EqTo y '[] = y
EqTo y (y ': xs) = EqTo y xs
EqTo y (x ': xs) = NotEqualFailure
data NotEqualFailure
type R = Same '[Int, Int]
f :: R
f = 3
最佳答案
实际上有一个错误,它 will be fixed在 GHC 的下一个版本中。
关于haskell - 在 GHCi 中键入家庭恶作剧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27490352/
我经常使用 ghci 进行少量计算,并使用 stack ghci 来处理我的实际项目。 为了使第一个更容易,我编写了一个 .ghci 文件,其中包含许多导入的模块,但其中一些模块不存在于我的堆栈项目中
我试图用这个来完善我的 GHCi:http://www.reddit.com/r/haskell/comments/144biy/pretty_output_in_ghci_howto_in_comm
我有一个 .ghci在我的本地项目目录中,另一个在我的 $HOME 中.当我做 stack ghci ,然后 $HOME/.ghci首先加载,然后是 $PWD/.ghci .是否可以只加载本地 .gh
在尝试将 ~/.ghci 文件更改为我的配置时,当我打开 GHCi 时出现此错误。 GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for h
所以我正在完成 Real World Haskell 的一些初始章节练习,我想知道 GHCi 中是否有一个选项可以让它在每个递归调用上显示带有参数的函数评估。例如,我写了一个简单版本的“map”,当我
我是 Haskell 的新手,在调试时我遇到了一个烦人的行为。 我使用 :break 添加断点 我运行 main 一切正常 我输入:继续完成执行 当我重新运行 main 时,断点不再命中,但断点没有被
从 ghc 7.6 更新到 7.10 后,您似乎无法 :m [Module]或 ghci> import [Module]其中 [Module.hs] 是您的手写模块文件,位于当前工作目录中。 似乎
我正在尝试编写一个 Erasthosthenes 函数的筛选器,该函数为用户提供从 2 到其上限的所有质数。所以我写了这段代码: main = do putStrLn "Upper Limit" g
这个问题在这里已经有了答案: How does GHCi pick names for type variables? (1 个回答) How are variable names chosen in
我现在应该真的知道这一点,但我不知道。我经常开发基于 Cabal 的软件包,并且刚刚成功运行了 cabal build .现在我想在 GHCi 中尝试一些东西。如果我运行 cabal repl ,然后
编写一个模块: module Foo where foo = 3.14 编译它: ghc -c Foo.hs 加载它: ghci -ignore-dot-ghci GHCi, version 7.8.
在检查不同整数类型的大小( minBound 、 maxBound )和“十进制表示的长度”时,我碰巧看到了一些奇怪的行为。 使用 GHCi: Prelude> :{ Prelude| let mi
考虑程序: l = [0..10] l' = map (+1) [0..10] 使用 GHCi 运行它,并键入 :sprint l 和 :sprint l' 将显示两个列表都未计算。但是,在运行 le
GHCi 中有没有办法基本上获得状态转储?我的意思是一个列表: 所有加载的运算符及其优先级、关联性和签名。 所有加载的类。 所有加载的数据、类型和新类型以及它们是哪些类的实例。 所有加载的函数都带有它
我刚开始学习 Haskell,很难理解 Haskell 程序的“流程”。 例如在 Python 中,我可以编写一个脚本,将其加载到解释器并查看结果: def cube(x): return x
A做了一个模块Timeit。我无法将其导入 GHCi。 模块: module Timeit (timeit, timeCatch) where import Data.Time.Clock timei
我刚刚安装了 Haskell Platform for Windows(版本 2011.2.0.1),并开始通过 HaskellQuestions.pdf 工作 第二个问题需要“x = 3”作为答案。
作为 Haskell 的新手,我正在努力解决以下差异(我确信这是有充分理由的)。也许我的问题只是源于对 GHCi 的误解,但当我能消除疑虑时,我晚上会睡得更好。 来了。如果,在将名称 foo 绑定(b
我正在试验 GHCi 的 :sprint命令。考虑以下: GHCi> xs = [1..10] :: [Int] GHCi> :sprint xs xs = _ GHCi> length xs 10
假设我有以下功能: minc = map (+1) natural = 1:minc natural 它似乎是这样展开的: 1:minc(1:minc(1:minc(1:minc(1:minc(1:m
我是一名优秀的程序员,十分优秀!