[Haskell-cafe] Fwd: Announcing a solution to the records problem
AntC
anthony_clayden at clear.net.nz
Thu Jan 29 08:47:25 UTC 2015
> Christopher Done <chrisdone <at> gmail.com> writes:
(Thanks Chris for suggesting the cafe might be a place to discuss this.)
I'm replying to your/Nikita's latest on ghc-devs.
> On Wed, Jan 28, 2015 at 4:48 PM, Nikita Volkov wrote:
>
> Chris, this is great! Looks like we can even get rid of the Rec prefix!
But, but! If we want anonymous records,
whose syntax is round brackets,
who don't want even a constructor,
we can do that already:
newtype X = X Coord; newtype Y = Y Coord;
point2D = (X 1, Y 1)
X # point2D
(I'm using (#) as the operator, but could be anything.)
class Has r l a | r l -> a where
(#) :: l -> r -> a
instance Has (l, l2) (a -> l) a where
_ # (x, _) = unL x
OK. The instances are yucky (and overlap).
(And need UndecideableInstances
so can't be done as type families.)
But they can all be defined once in the library,
up to some ridiculous size of tuples.
Generating the newtype decls
and their UnL instance
seems like a job for TH.
We can get more label-like with:
newtype Z a = Z a
instance (a' ~ a) => Has (l a', l2, l3) (a -> l a) a' where
_ # (x, _, _) = unL x
Z # (Z 7, X 1, Y 1)
(There's also the awkward oneple's to find nice syntax for.)
>> 2015-01-29 0:26 GMT+03:00 Christopher Done <chrisdone at gmail.com>:
>>
>> There’s too much to absorb in this discussion at the moment ...
(+1)
>> Given that this is very similar to TRex ...
>>
>> type Point2D = Rec (x::Coord, y::Coord)
>> point2D = (x=1, y=1) :: Point2D
>> (#x point)
AntC
More information about the Haskell-Cafe
mailing list