何时(如果曾经)可以部分应用类型同义词? [英] When (if ever) can type synonyms be partially applied?

查看:146
本文介绍了何时(如果曾经)可以部分应用类型同义词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然有点心不在焉,我写了类似于以下内容:

  { - #LANGUAGE Con​​straintKinds# - } 
{ - #LANGUAGE TypeFamilies# - }

class Foo f where
type Bar f :: *
retbar :: Bar f - > IO f

类型Baz f =(Foo f,Eq f)

- WithBar :: * - > (* - >约束) - > * - >约束
类型WithBar bcf =(cf,Bar f〜b)

实例Foo()其中
类型Bar()=()
retbar = return

naim :: WithBar()Baz u =>你呃 - 为什么我可以这样做?
naim = retbar()

main = naim :: IO()

只有成功编译之后,我才意识到不应该实际工作: Baz 被定义为具有一个参数的类型同义词,但我在这里没有直接的论据。通常,GHC会咆哮我类型同义词'Baz'应该有1个参数,但当我尝试类似的时候没有给出



现在,请不要误解我的意思:我真的很希望能够编写它,并且很容易看出它在这个特定示例中的工作原理(简单地将 WithBar 会产生签名 naim ::(Foo u,Bar u〜())=> IO u ,这当然很好),但是我不明白为什么它实际上就是这样工作的。它可能只是 ghc-7.8.2 中的一个bug来允许这个吗?

解决方案

您的文件在GHC 7.8中编译,但在GHC 7.10中出现错误:
$ b


类型同义词'Baz'应该有1参数,但没有给出

在'naim'的签名中:naim :: WithBar()Baz u => IO u


添加 -XLiberalTypeSynonyms 修复错误。因此,这是7.8中的一个错误。


Apparently a bit absent-mindedly, I wrote something like the following:

{-# LANGUAGE ConstraintKinds     #-}
{-# LANGUAGE TypeFamilies        #-}

class Foo f where
  type Bar f :: *
  retbar :: Bar f -> IO f

type Baz f = (Foo f, Eq f)

  -- WithBar :: * -> (*->Constraint) -> * -> Constraint
type WithBar b c f = (c f, Bar f ~ b)

instance Foo () where
  type Bar () = ()
  retbar = return

naim :: WithBar () Baz u => IO u  -- why can I do this?
naim = retbar ()

main = naim :: IO ()

Only after successfully compiling, I realised this shouldn't actually work: Baz is defined as a type synonym with one argument, but here I use it without a direct argument. Usually GHC barks at me Type synonym ‘Baz’ should have 1 argument, but has been given none when I try something like that.

Now, don't get me wrong: I would really like being able to write that, and it's easy enough to see how it could work in this particular example (simply inlining WithBar would yield the signature naim :: (Foo u, Bar u ~ ()) => IO u, which is certainly fine), but what I don't understand why it actually works just like that here. Is it perhaps only a bug in ghc-7.8.2 to allow this?

解决方案

Your file compiles in GHC 7.8, but in GHC 7.10 I get an error:

Type synonym ‘Baz’ should have 1 argument, but has been given none

In the type signature for ‘naim’: naim :: WithBar () Baz u => IO u

Adding -XLiberalTypeSynonyms fixes the error. Therefore, this is a bug in 7.8.

这篇关于何时(如果曾经)可以部分应用类型同义词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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