存在量词默默地破坏了模板Haskell(makeLenses)。为什么? [英] Existential quantifier silently disrupts Template Haskell (makeLenses). Why?

查看:127
本文介绍了存在量词默默地破坏了模板Haskell(makeLenses)。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  { - #LANGUAGE TemplateHaskell# - } 
{ - #LANGUAGE ExistentialQuantification# - }

模块玩具其中

导入Control.Lens

数据Bar = Bar {_barish :: String}
data Foo =全部显示a => Foo {_fooish :: a}

$(makeLenses''Bar)
$(makeLenses''Foo)

x = barish
y = fooish

我收到以下错误消息:

  Toy.hs:15:5:
不在范围内:`fooish'
也许你的意思是'_fooish'(第9行)

这是我第一次尝试使用存在量词;我不知道为什么这些功能的组合会打破。更令人担忧的是,为什么我不会收到有关makeLenses失败的错误消息?我跑了 runhaskell Toy.hs

解决方案

你的功能_fooish。如果你试图这样做,你会得到这样的错误:

$ $ $ pre $ $ code>由于转义类型,不能使用记录选择器_fooish作为函数变量
可能的修正:使用模式匹配语法来代替
在表达式中:_fooish



<所以镜头不能为你生成镜头。为什么它没有提供错误?那么,有时候你有更多的领域可以生成镜头。在这里看起来情况并非如此,但我认为通常makeLine只是跳过一些不可能做的事情,并尝试生成其余的东西。

I have this file:

{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ExistentialQuantification #-}

module Toy where

import Control.Lens

data Bar = Bar { _barish :: String }
data Foo = forall a. Show a => Foo { _fooish :: a }

$(makeLenses ''Bar)
$(makeLenses ''Foo)

x = barish
y = fooish

and I get the following error message:

Toy.hs:15:5:
    Not in scope: `fooish'
    Perhaps you meant `_fooish' (line 9)

This is my first time attempting to use existential quantifiers; I have no idea why this combination of features breaks. Even more worryingly, why do I get no error message about makeLenses failing? I ran runhaskell Toy.hs

解决方案

You can't actually use your function _fooish. If you try to do that, you get the error:

Cannot use record selector `_fooish' as a function due to escaped type variables
Probable fix: use pattern-matching syntax instead
In the expression: _fooish

So lens can't generate a lens for you. Why doesn't it give an error? Well, sometimes you have additional fields for which it's possible to generate lenses. It seems this not the case here, but I think in general makeLenses just skips everything that is impossible to do and tries to generate the rest.

这篇关于存在量词默默地破坏了模板Haskell(makeLenses)。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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