is there a possibility to create an fmap for records so that I can apply the same function to record fields of similar bur different types
Let say I have a record field type Item
and a record X
and function transform
type Item<'a, 'b> = Item of 'a * 'b
let transform (i: Item<'a, 'b>) : Item<'a, string> =
let (Item (x, y)) = i
Item (x, sprintf "%A" y)
type X<'a> = {
y: Item<'a, int>
z: Item<'a, bool>
}
with
member inline this.fmap(f) =
{
y = f this.y
z = f this.z
}
now the line z = f this.z
complains that the given type should be of Item<'a, int>
but its of type Item<'a, bool>
. Obviously as the type infererrer
has decided that the function f
is of type Item<'a, int> -> Item<...>
however i want f
to be applied polymorphic. How can I get this done?
Evil type hacks are welcome!