-
Notifications
You must be signed in to change notification settings - Fork 19
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
Can we use type classes to eliminate need for attr
and attr'
functions?
#11
Comments
In fact, looking at the code for Selection.purs I see that there's the
Adding a third instance allows me to pass functions into the regular
But I guess it would be better to have some restrictions on the return value of the function... |
Hey, glad you like the library and thanks for your contributions! This seems like a great idea, and I've played around with trying to do something like it, but I've run into problems that I don't know how to solve. As you mentioned, the tricky part is that you want to constrain the types involved... actually not just the return value class Existing s where
-- ...
attr2 :: forall d v. (AttrValue2 v d) => String -> v -> s d -> D3Eff (s d)
-- ... with the idea that it will be able to supersede class AttrValue2 v d So to have it do the duty of instance liftAttrVal :: (AttrValue v) => AttrValue2 v d That seems to work fine; you can replace all instances of instance attrValFun1 :: (AttrValue v) => AttrValue2 (d -> v) d Unfortunately this doesn't seem to work as expected. instance attrValFun2 :: (AttrValue v) => AttrValue2 (d -> Number -> v) d And thereby supersede |
Thanks for the response! Is it worth logging an issue about multi-parameter typeclasses over at purescript? |
Yeah, definitely worth filing a bug on it! |
If you make an issue, @-mention me so I can watch it and participate in the discussion. |
Actually, I'm going to pass on filing the bug on the purescript compiler myself. I had a quick go at making a minimal repro of the problem... but quickly realised when things started going wrong I couldn't tell whether it was my fault or the compiler. While it would be a great exercise for me to get to the bottom of it, I just don't have time at the moment. Sorry! |
Many thanks for creating purescript-d3, I'm having fun learning purescript by trying to convert js d3 demos.
I'm a purescript newbie just learning about type classes so sorry if I'm naive, but I wonder if it would be possible to create a typeclass for the possible arguments to the Selection
attr
functions, such that we can have a single overloadedattr
that takes a string, a number or a function? I miss that aspect of the original javascript interface.Seems simple enough to make a toy example - what am I missing?
Thanks again!
The text was updated successfully, but these errors were encountered: