可以使用UndecidableInstances pragma本地对编译终止有全局影响吗? [英] Can using UndecidableInstances pragma locally have global consequences on compilation termination?

查看:231
本文介绍了可以使用UndecidableInstances pragma本地对编译终止有全局影响吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设Haskell库设计者决定使用 UndecidableInstances 。库编译良好。现在假设一些程序使用库(如定义其类型类的一些实例),但不使用扩展。是否会发生编译失败(不会终止)?

Suppose a Haskell library designer decides to use UndecidableInstances for some reason. The library compiles fine. Now suppose some program uses the library (like defines some instances of its type classes), but doesn't use the extension. Can it happen that the compilation fails (doesn't terminate)?

如果这种情况发生,我很高兴看到一个例子。例如, mtl 使用 UndecidableInstances 很多,是否可以编写依赖于 mtl (或使用扩展名的任何其他标准库)的程序,不使用 UndecidableInstances

If such a scenario can happen, I'd be happy to see an example. For example, as mtl uses UndecidableInstances a lot, is it possible to write a program that depends on mtl (or any other standard library that uses the extension), doesn't use UndecidableInstances itself, but fails to compile because of undecidability?

推荐答案

很好的问题!

一般来说这是可能的。考虑此模块:

In general this is certainly possible. Consider this module:

{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances #-}

module M where

class C a b | a -> b where
  f :: a -> b

instance C a b => C [a] [b]
  where f = map f

精细。但是,如果您导入此模块并定义

It compiles by itself just fine. However, if you import this module and define

g x = x + f [x]

您将获得

Context reduction stack overflow; size = 201
Use -fcontext-stack=N to increase stack size to N
  C [b] b
In the second argument of `(+)', namely `f [x]'
In the expression: x + f [x]
In an equation for `g': g x = x + f [x]






关于mtl实例,我看不到这样的东西是可能的,但我也没有证明不是。


Regarding the mtl instances, I don't see how something like this is possible, but I also don't have a proof that it's not.

这篇关于可以使用UndecidableInstances pragma本地对编译终止有全局影响吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆