Ticket #46 (closed defect: wontfix)

Opened 3 years ago

Last modified 22 months ago

Signature of backpermute is unnessesary restrictive

Reported by: Khudyakov Owned by:
Priority: minor Milestone:
Version: Keywords:
Cc: alexey.skladnoy@…

Description

I think that type signature of backpermute is bit restrictive

backpermute :: (Vector v a, Vector v Int) ⇒ v a → v Int → v a

More liberal signature makes perfect sense. If vector are not the same things are still perfectly sensible.

backpermute :: (Vector v a, Vector v' Int) ⇒ v a → v' Int → v a

I encountered this when I tried to permute generic vector using unboxed one.

Of course there may be performance considerations, implementation difficulties etc

Change History

Changed 3 years ago by rl

This signature also makes perfect sense:

backpermute :: (Vector v a, Vector v' a, Vector v' Int) => v a -> v' Int -> v' a

I'm not sure what to do here. It's not just backpermute, other operations (most notably the update and accumulate families) can also be generalised in this way but it's not really obvious what signatures to export from the specialised modules. I'll try to come up with some kind of scheme. Suggestions would be greatly appreciated!

Changed 3 years ago by Khudyakov

Well this one is nice too. And it's not possible to became more generic.

backpermute :: (Vector v a, Vector v'' a, Vector v' Int) => v a -> v' Int -> v'' a

There is another concert. Function above doesn't fix return type so additional type annotation may become nessesary. Maybe it should be named backpermuteGen or something along this lines and old function should retain old signature

With specialized modules it's easy. They are specialized then export specialized signatures like

backpermute :: Vector a -> Vector Int -> Vector a

If they are too restrictive you have to import from D.V.Generic. It's not too paintful I think.

Changed 3 years ago by Khudyakov

Also if signature for backpermute is OK then following map is acceptable too:

map :: (Vector v a, Vector v' b) ⇒ (a → b) → v a → v' b

This applies to every function which have more than on vector in signature

Changed 3 years ago by rl

So I thought about this for a while and I'm not sure what to do. You are quite right that it is possible to generalise the signatures for all functions which take more than one vector. However, doing so would make Data.Vector.Generic rather unusable - you'd need to add explicit signatures everywhere when writing generic vector code. This is something I wouldn't be happy with. One the other hand, is having to add a call to convert really so bad? At least it draws attention to the fact that you're changing the vector type.

I'm really not sure what to do. Any input is appreciated!

Changed 2 years ago by Khudyakov

I think it's better described as totally unusable. I think there only two sane options. First one is to left everything as it is and just use convert. Second is to add OverlyGeneric? module which will contain function with most generic signatures. Then function from Data.Vector will be just a specializations. However I'm not sure is it better that first option

Changed 2 years ago by rl

  • priority changed from major to minor

Changed 22 months ago by rl

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

Since the status quo doesn't seem to be a bad choice, I'll close this as won't fix. Please yell if you really want something done here.

Note: See TracTickets for help on using tickets.