The existential quantifier silently destroys the Haskell (makeLenses) pattern. What for?

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 attempt to use existential quantifiers; I have no idea why this combination of functions breaks down. Even more worrying, why am I not getting the error message associated with the makeLenses error? I ran runhaskell Toy.hs

+2
source share
1 answer

You cannot use your _fooish function. If you try to do this, you will receive an error message:

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

Therefore, the lens cannot create a lens for you. Why doesn't he give an error? Well, sometimes you have extra fields for which you can create lenses. It doesn't seem to be that way, but I think that overall makeLenses just skips everything that cannot be done and tries to generate the rest.

+5
source

Source: https://habr.com/ru/post/951046/


All Articles