KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Consider the following type-class: class Listable a where asList :: a t -> [t] It's easy enough to create instances for types with one parameter: instance Listable [] where asList = id instance Listable Maybe where asList (Just x) = [x] asList Nothing = [] Now how would I make an instance for a pair with two identical type parameters? Of course I could do some wrapping: data V2 a = V2 a a v2 (p,q) = V2 p q instance Listable V2 where asList (V2 p q) = [p,q] Now I could write things like asList $ v2 (47, 11) , but this kind of defeats the purpose. Is there a way to limit the type of pair to cases where both type parameters are equal, and to write a Listable instance for that? If not, what is the usual workaround?
Tags (comma-separated)
Save Edits
Cancel