2

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

4

1 回答 1

5

你实际上不能使用你的函数_fooish。如果您尝试这样做,则会收到错误消息:

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

所以镜头不能为你生成镜头。为什么它不给出错误?嗯,有时您有额外的字段可以生成镜头。这里似乎不是这种情况,但我认为总的来说 makeLenses 只是跳过所有不可能做的事情并尝试生成其余的。

于 2013-06-22T23:05:52.767 回答