{"action":"closed","issue":{"url":"https://api.github.com/repos/ekmett/linear/issues/64","labels_url":"https://api.github.com/repos/ekmett/linear/issues/64/labels{/name}","comments_url":"https://api.github.com/repos/ekmett/linear/issues/64/comments","events_url":"https://api.github.com/repos/ekmett/linear/issues/64/events","html_url":"https://github.com/ekmett/linear/issues/64","id":56812781,"number":64,"title":"Too many constraints when trying to be generic over vectors","user":{"login":"yongqli","id":67243,"avatar_url":"https://avatars.githubusercontent.com/u/67243?v=3","gravatar_id":"","url":"https://api.github.com/users/yongqli","html_url":"https://github.com/yongqli","followers_url":"https://api.github.com/users/yongqli/followers","following_url":"https://api.github.com/users/yongqli/following{/other_user}","gists_url":"https://api.github.com/users/yongqli/gists{/gist_id}","starred_url":"https://api.github.com/users/yongqli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yongqli/subscriptions","organizations_url":"https://api.github.com/users/yongqli/orgs","repos_url":"https://api.github.com/users/yongqli/repos","events_url":"https://api.github.com/users/yongqli/events{/privacy}","received_events_url":"https://api.github.com/users/yongqli/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-02-06T13:41:10Z","updated_at":"2015-02-06T13:42:11Z","closed_at":"2015-02-06T13:42:11Z","body":"I'm having a problem where trying to write functions that are generic in which vector type to use (`V0`, `V1`, `V2`, etc), the constraints explode. For example:\r\n\r\n    storeInV :: (Applicative v, Unbox (v Int), Unbox (v Double), Unbox (v String), \r\n                 Num (v Int), Num (v Double))\r\n             => Int -> (VU.Vector (v Int), VU.Vector (v Double), VU.Vector (v String))\r\n    storeInV n =\r\n      let\r\n        x = VU.replicate n 1\r\n        y = VU.replicate n 2\r\n        z = VU.replicate n (pure \"a\")\r\n      in (x, y, z)\r\n\r\nIf I have a function that calls `storeInV`, it has to \"inherit\" all of the constraints. All those constraints quickly become unmanageable.\r\n\r\nI see two ways to solve this problem:\r\n1) Find some way to express in Haskell the idea of a \"Unboxing\" container `v` such that any `Unbox a` implies `Unbox (v a)`. Perhaps the `constraints` package can help, but I don't know how to use it.\r\n\r\n2) Somehow unify all `V0`, `V1`, etc under a single type, `Vn`. Perhaps a closed type family or something. We write an `Unbox` instance for `Vn`, and then the type signature for the above can simply be:\r\n\r\n    storeInV :: Int -> (VU.Vector (Vn dim Int), VU.Vector (Vn dim Double), VU.Vector (Vn dim String))\r\n\r\nI would be interested in working on this, but I don't know enough about advanced Haskell type system topics to know how to proceed. Could someone can point me to the relevant resources?"}}