-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subhask vector type variadic function #51
Comments
Very interesting question! Thanks! There are several reasons for the
Furthermore, I think there is a simpler solution for what you're trying to do than variadic functions. Every free module with n dimensions is isomorphic to an n-tuple. So why not just provide functions/type classes that freely convert between the two types. Then something equivalent to your example code would read:
That's a very minor syntatic overhead, but is a bit more intuitive and gets you nicer error messages. I'm open to counterarguments, but at this point variadic functions just seem like they'd complicate the code for little benefit. |
yes for run time values use the unsafe version. And it is isomorphic to an n-tuple but can you have n-tuples in haskell? also isn't converting it a pain and bounded? |
GHC supports tuples up to size 64. |
yes and I already have a 100 sized compile time vector that I am using, imagine you want a flat matrix that's 8x9 that would already exceed the limit. And you have to write an instance for every tuple no? that's alot of code, I wish ghc's tuple was more generic a bit like an type level list, actually now that I think about it that's exactly what you need and it might be much better than a variadic function , check this out |
I guess it never occured to me that people might want such large compile Yes, an HList could serve this purpose well. On Thu, Jul 7, 2016 at 12:09 AM, Bassel Mabsout [email protected]
|
I was looking a bit through the examples in the subhask github repo and I saw that a function called unsafeToModule that takes a list and creates the vector with a statically defined size is being used which is what I was doing when I was playing around with creating a sized vector but then I came across Variadic functions so I wrote one to be safer. the sized vector module I wrote is attached. (I actually had an issue where my list wasn't of the right size)
SizedV.hs.zip
mkN is the function and can be used as such:
with -XPartialSignatures enabled it is useful as it is not needed to say that _ is 5 it is automatically computed and editors can show you the value.
(Also I think the class Make can be simplified but I tried to write a simple instance and failed so I stole an old fixed size vector's implementation which uses peano numbers to encode length and modified it to my needs)
Edit:
actually here's a simple version of the variadic function and it works as intended
class Make n a r | r -> a where
make :: SizedV n a -> r
The text was updated successfully, but these errors were encountered: