OK, I have a solution. Ugly, but it compiles. MyStruct actually has quite a few fields but I only need to access the polymorphic field 4 times.
So for the functions that needed that I wrote: f myS@(MyStruct value _ _ _ ) and then could use value. I could then use the usual record accessors on myS to get the other (non-polymorphic) data. I guess that is what GHC was hinting at when it suggested pattern matching. That is, pattern matching could extract a value that no functions are apparently allowed to touch. All head spinning to me. Thanks for the (as always) fast and useful advice! Kevin On Sep 26, 2:00 pm, Kevin Jardine <kevinjard...@gmail.com> wrote: > OK, thanks for this advice. > > The type definition compiles, but when I try to actually access > myField, the compiler says: > > Cannot use record selector `myField' as a function due to escaped type > variables > Probable fix: use pattern-matching syntax instead > > So I took the hint and wrote a new pattern matching accessor function: > > getMyField (MyStruct value) = value > > and I get: > > Inferred type is less polymorphic than expected > Quantified type variable `a' escapes > When checking an existential match that binds > value :: a > > Any further suggestions? > > On Sep 26, 1:09 pm, Daniel Fischer <daniel.is.fisc...@web.de> wrote:> On > Sunday 26 September 2010 12:53:46, Michael Snoyman wrote: > > > > data MyStruct = forall a. MyTypeClass a => MyStruct {myField :: a} > > > Note that that requires > > {-# LANGUAGE ExistentialQuantification #-} > > _______________________________________________ > > Haskell-Cafe mailing list > > haskell-c...@haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe > > _______________________________________________ > Haskell-Cafe mailing list > haskell-c...@haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe