- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在为下面定义的异构列表定义 Show 实例时遇到问题:
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE FlexibleInstances #-}
import Data.Kind
data HList xs where
HNil :: HList TNil
(::^) :: a -> HList as -> HList (a :^ as)
data TypeList = TNil | (:^) Type TypeList
instance Show (HList TNil) where
show HNil = "[]"
我想给HList xs一个show实例,如果Typelist xs中的所有类型都有一个Show Instance。我想应该可以写出类似的东西
instance (Show a, _) => Show (HList a :^ as) where
show (x ::^ xs) = show x ++ show xs
但我不确定该填什么_。
PS:如果你在 ghci 中尝试这个,不要忘记添加语言扩展
:set -XTypeInType -XTypeOperators
最佳答案
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
import Data.Kind
infixr 5 ::^
data HList xs where
HNil :: HList TNil
(::^) :: a -> HList as -> HList (a :^ as)
data TypeList = TNil | (:^) Type TypeList
instance Show (HList TNil) where
show HNil = "HNil"
instance (Show a, Show (HList as)) => Show (HList (a:^as)) where
showsPrec p (x::^xs) = showParen (p>5)
$ showsPrec 6 x . ("::^"++) . showsPrec 5 xs
main :: IO ()
main = print ((2 :: Int) ::^ "bla" ::^ HNil)
2::^"bla"::^HNil
关于haskell - 异构列表的显示实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50318757/
我有一个 NSTreeController (向 NSOutlineView 提供内容)。我希望顶级对象属于一个类,而所有其他对象(因此,任何级别的子对象)属于另一个类。解决这个问题的最佳方法是什么?
我有一个如下所示的 GADT data MyTypes = MyInt | MyDouble data Test (t :: MyTypes) where A :: Int -
我需要一个高效的异构数组,其中第一个元素是 int,其余是 float。然而,创建它之后,基本的数组操作就会呈爆炸式增长。 A = np.zeros(1, dtype='i4, f4, f4') B
我有一个 pandas DataFrame,其中包含需要拆分成平衡切片的字符串和浮点列,以便训练 sklearn 管道。 理想情况下,我会使用 StratifiedKFold在 DataFrame 上
是否有一种异构容器的形式,能够存储例如不同的基本类型(例如int、float、double)? 最终我希望能够在计算中使用元素而无需显式引用类型,例如 auto res = a + b,其中操作数 a
假设我有一个结构(或类),如下所示: struct _particle { std::vector vx , vy; std::vector id; std::vector rx, ry; }; ty
我在将具有 > 22 列的表专门映射到 case class 时遇到问题,假设您有以下代码 import slick.driver.PostgresDriver import scala.slick.
我是一名优秀的程序员,十分优秀!