2013-06-22 22 views
2

我有這個文件:存在量詞默默地破壞模板Haskell(makeLenses)。爲什麼?

{-# 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 

,我得到了以下錯誤消息:

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

這是我第一次嘗試使用存在量詞;我不知道爲什麼這些功能的組合會打破。更令人擔憂的是,爲什麼我不會收到有關makeLenses失敗的錯誤消息?我跑runhaskell Toy.hs

回答

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 

所以鏡頭不能爲你生成鏡頭。爲什麼它沒有提供錯誤?那麼,有時候你有更多的領域可以生成鏡頭。在這裏看起來情況並非如此,但我認爲通常makeLine只是跳過一些不可能做的事情,並嘗試生成其餘的東西。

相關問題