Existential quantifier silently disrupts Template Haskell (makeLenses). Why?
Asked Answered
E

1

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

Elka answered 22/6, 2013 at 22:55 Comment(0)
W
5

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.

Whorled answered 22/6, 2013 at 23:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.