Records in Haskell
b.hilken at ntlworld.com
Mon Nov 7 22:41:18 CET 2011
> The problem with this approach is that different labels do not have
> different representations at the value level.
I think this is an advantage, because it means you don't have to carry this stuff about at runtime.
> This allows me to pattern match records, since I can construct record
> patterns that contain fixed labels:
> X :& MyName1 := myValue1 :& MyName2 := myValue2
> I cannot see how this could be done using kind String. Do you see a
> solution for this?
> A similar problem arises when you want to define a selector function.
> You could implement a function get that receives a record and a label as
> arguments. However, you could not say something like the following then:
> get myRecord MyName1
> Instead, you would have to write something like this:
> get myRecord (Label :: MyName1)
Just define a constant
myName1 = Label :: MyName1
for each label you actually use, and you can use it in both get and pattern matching
More information about the Glasgow-haskell-users