haskell - 默认约束类型被忽略

标签 haskell default type-constraints

我在定义默认约束时遇到了一个奇怪的问题。如果约束是单位,则不选择默认实例。在所有其他情况下,它按预期工作。

{-# LANGUAGE TypeFamilies, ConstraintKinds #-}
import qualified GHC.Exts as E

class Expression a where
  type Constr a v :: E.Constraint
  --type Constr a v = ()         -- with this line compilation fails
  --type Constr a v = v ~ v      -- compiles
  wrap :: Constr a v => a -> Maybe v

instance Expression () where
  wrap () = Just undefined

main = print (wrap () :: Maybe Int)

有人可以澄清类型检查器行为的原因吗?

最佳答案

这是 7.4.1 中关联类型默认值的错误。几周前,我在#haskell 上被告知这是一个已修复的已知错误,但我在 GHC trac 上找不到它的提及。

关于haskell - 默认约束类型被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10381278/

相关文章:

haskell - 使用 foldr 的功能太急切了

haskell - NixOS 和 ghc-mod - 找不到模块

Xcode 4.2.1 ARC 问题

c# - 实现具有类型约束的通用接口(interface)

generics - F# 类型参数缺少约束

f# - 为什么空检查会导致 F# 中的等式约束?

haskell - 当 Emacs 23 Haskell 编译 (C-c C-l) 进入无休止的过程时该怎么办?

haskell - 值的类型签名

php - 更改默认的 Dreamweaver 模板

c++ - 如何将运算符作为默认仿函数参数传递?