小编Rav*_*mio的帖子

为什么在C99之前混合声明和代码被禁止?

我最近成为大学课程的助教,主要教授C. C90课程标准化,主要是由于广泛的编译器支持.具有以前Java经验的C新手的一个非常令人困惑的概念是变量声明和代码可能不在块内混合的规则(复合语句).

最终用C99解除了这个限制,但我想知道:有人知道它为什么会出现在那里吗?它是否简化了可变范围分析?它是否允许程序员指定堆栈应该为新变量增加哪些程序执行点?

我认为语言设计师如果完全没有任何目的就不会增加这样的限制.

c c99 c89

40
推荐指数
3
解决办法
4383
查看次数

数据类型列表:"无法从上下文中推导出(a~TomeType)(SomeTypeclass a)"

我对Haskell的类型系统有以下问题:我试图声明一个数据类型并从函数返回包含此类型元素的列表.不幸的是,即使是最小的测试用例如

data SampleType = SampleTypeConstructor

instance Show SampleType where
    show x = "(SampleType)"

stList :: (Show a) => [a]
stList = [(SampleTypeConstructor)]

main = do {
    putStrLn (show stList)
}
Run Code Online (Sandbox Code Playgroud)

失败,并出现以下来自ghc-7.0.2和ghc-7.1.20110327的错误消息:

tcase.hs:7:12:
    Could not deduce (a ~ SampleType)
    from the context (Show a)
      bound by the type signature for stList :: Show a => [a]
      at tcase.hs:7:1-34
      `a' is a rigid type variable bound by
          the type signature for stList :: Show a => [a] at tcase.hs:7:1
    In the expression: …
Run Code Online (Sandbox Code Playgroud)

haskell types

19
推荐指数
2
解决办法
7152
查看次数

标签 统计

c ×1

c89 ×1

c99 ×1

haskell ×1

types ×1