How to write Haskell style code assuming type classes ?
MarcWeber opened this issue · 1 comments
In Haskell you can do
foo: Show a; a -> IO ()
foo = print . show
-- same as foo a = print (show a)
How would such be done with classy ? I am still new to nim.
The point is thaht Show is the typeclass and a is the type parameter.
The best this library can give you at the moment is probably something like this (assuming print
is defined elsewhere):
typeclass Show, A:
# proc show(a: A): string
proc foo[A](a: A) = print(show(a))
Show
doesn't actually do anything here, though. At the moment, imposing actual typeclass constraints is not supported. I toyed with the idea, but couldn't figure how to find some kind of canonical and unique representation for a type, without which the whole thing seems impossible.
As an improvement to the above It's possible we can uncomment show
declaration in the typeclass (I heard the corresponding issue got squished some time ago). You can also try and write a concept for Show
that would check that show(a)
compiles, which can be checked in the signature.