Ticket #48 (closed enhancement: wontfix)

Opened 2 years ago

Last modified 2 months ago

Generate Unbox instances using TH

Reported by: Khudyakov Owned by:
Priority: minor Milestone:
Version: Keywords:
Cc: alexey.skladnoy@…, bgamari, PHO, haskell.org@…

Description

It would be very nice and useful feature. Tuple-like data types are very frequently used.

data Point a = Point a a

It's not different from (a,a) and therefore could have Unboxed instance. However writing such instance is highly impractical. Obvious workaround is to make Point a newtype and to use GeneraliedNewtypeDeriving?:

newtype Point a = Point (a,a)

deriving instance (U.Unbox a) => U.Unbox             (Point a a)
deriving instance (U.Unbox a) => G.Vector  U.Vector  (Point a a)
deriving instance (U.Unbox a) => M.MVector U.MVector (Point a a)

This approach looks a little ugly to me. And if newtype couldn't be used for any reason it won't work.

Since to my knowledge TH doesn't offer any control on inlining it's not possible implement.

Change History

Changed 2 years ago by Khudyakov

  • cc alexey.skladnoy@… added

Changed 2 years ago by rl

  • milestone set to 0.8

Yes, this would be good! TH actually knows about INLINE pragmas (that's a relatively recent change) so it would be quite feasible, too. I'll gladly accept patches :-)

However, I suspect that with the generics support in GHC 7.2 we might not even need TH for this. I think it's best to wait and see if that's really the case.

Changed 2 years ago by rl

  • milestone 0.8 deleted

Changed 17 months ago by bgamari

  • cc bgamari added

Changed 15 months ago by PHO

  • cc PHO added

Changed 15 months ago by liyang

Just noticed this ticket. I made a vector-th-unbox package that does exactly this. Would be quite happy for it to be absorbed into vector.

See https://github.com/liyang/vector-th-unbox and http://hackage.haskell.org/package/vector-th-unbox . The github repo is more up to date.

Changed 15 months ago by liyang

  • cc haskell.org@… added

Changed 14 months ago by Khudyakov

Liyang, thank you for the work!

However I think it's better to keep deriving code in the separate package to avoid pulling TH dependency

Changed 2 months ago by liyang

  • status changed from new to closed
  • resolution set to wontfix

In that case I think this can be closed.

Note: See TracTickets for help on using tickets.