Reputation: 4628
Is there a way to define a type/alias representing a row polymorphic record?
So given this example
tester :: forall r. {val :: Int | r} -> Int
tester a =
a.val
callTester = tester {val: 1, b: 2}
I want to define the record type as an alias. Something like
type Val = forall r. {val :: Int | r}
tester :: Val -> Int
tester a =
a.val
callTester = tester {val: 1, b: 2}
But that will not compile.
For larger records and more complex functions defining the types multiple times leads to quite a lot of noise. It would be nice to factor this out.
e.g. fn :: a -> b -> a
I have to define a
twice
For non-polymorphic records its simple but I explicitly want to allow records with additional fields that are not know upfront.
Thanks
Upvotes: 2
Views: 328
Reputation: 4628
Here is how I got it working for the example above.
type Val r = {val :: Int | r}
tester :: forall a. Val a -> Int
tester v =
v.a
callTester = tester {val: 1, b: 2}
So define a type, and have the forall
on the functions using the type
Upvotes: 4