[Haskell-cafe] Polymorphic record field?

Kevin Jardine kevinjardine at gmail.com
Sun Sep 26 06:51:06 EDT 2010


I have an almost finished Haskell program and I discovered that I
needed to change the type of one record field.

The problem is that the new type is polymorphic.

Being new to Haskell, I simply changed:

data MyStruct = MyStruct {myField :: myType}

to

data MyStruct = MyStruct {myField :: MyTypeClass a => a}

and then ended up in a maze of compiler messages about Rank N types
and "Inferred type is less polymorphic than expected".

Upon Googling for this issue, I have discovered that Haskell records
do not support polymorphic types and that there is a large literature
about options to fix this.

Although the literature is interesting, what I am looking for right
now is a simple fix.

I really don't want to have to rewrite all the many type and value
references to MyStruct in my code.

Is there a way to redefine the definition of MyStruct without changing
any of my other code?

If I have to change the way myField is accessed, I can handle that.
What I don't really want to do is change the type signature of
functions that take MyStruct parameters (of which there are many).

Is this possible? What is the simplest way to do this?

Kevin


More information about the Haskell-Cafe mailing list